attr-mode.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // RUN: %clang_cc1 -triple i686-pc-linux-gnu -DTEST_32BIT_X86 -fsyntax-only \
  2. // RUN: -verify %s
  3. // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -DTEST_64BIT_X86 -fsyntax-only \
  4. // RUN: -verify %s
  5. // RUN: %clang_cc1 -triple powerpc64-pc-linux-gnu -DTEST_64BIT_PPC64 -fsyntax-only \
  6. // RUN: -verify %s
  7. typedef int i16_1 __attribute((mode(HI)));
  8. int i16_1_test[sizeof(i16_1) == 2 ? 1 : -1];
  9. typedef int i16_2 __attribute((__mode__(__HI__)));
  10. int i16_2_test[sizeof(i16_1) == 2 ? 1 : -1];
  11. typedef float f64 __attribute((mode(DF)));
  12. int f64_test[sizeof(f64) == 8 ? 1 : -1];
  13. typedef int invalid_1 __attribute((mode)); // expected-error{{'mode' attribute takes one argument}}
  14. typedef int invalid_2 __attribute((mode())); // expected-error{{'mode' attribute takes one argument}}
  15. typedef int invalid_3 __attribute((mode(II))); // expected-error{{unknown machine mode}}
  16. typedef struct {int i,j,k;} invalid_4 __attribute((mode(SI))); // expected-error{{mode attribute only supported for integer and floating-point types}}
  17. typedef float invalid_5 __attribute((mode(SI))); // expected-error{{type of machine mode does not match type of base type}}
  18. typedef int invalid_6 __attribute__((mode(12))); // expected-error{{'mode' attribute requires an identifier}}
  19. typedef unsigned unwind_word __attribute((mode(unwind_word)));
  20. int **__attribute((mode(QI)))* i32; // expected-error{{mode attribute}}
  21. typedef _Complex double c32 __attribute((mode(SC)));
  22. int c32_test[sizeof(c32) == 8 ? 1 : -1];
  23. typedef _Complex float c64 __attribute((mode(DC)));
  24. #ifndef TEST_64BIT_PPC64 // Note, 'XC' mode is illegal for PPC64 machines.
  25. typedef _Complex float c80 __attribute((mode(XC)));
  26. #endif
  27. // PR6108: Correctly select 'long' built in type on 64-bit platforms for 64 bit
  28. // modes. Also test other mode-based conversions.
  29. typedef int i8_mode_t __attribute__ ((__mode__ (__QI__)));
  30. typedef unsigned int ui8_mode_t __attribute__ ((__mode__ (__QI__)));
  31. typedef int i16_mode_t __attribute__ ((__mode__ (__HI__)));
  32. typedef unsigned int ui16_mode_t __attribute__ ((__mode__ (__HI__)));
  33. typedef int i32_mode_t __attribute__ ((__mode__ (__SI__)));
  34. typedef unsigned int ui32_mode_t __attribute__ ((__mode__ (__SI__)));
  35. typedef int i64_mode_t __attribute__ ((__mode__ (__DI__)));
  36. typedef unsigned int ui64_mode_t __attribute__ ((__mode__ (__DI__)));
  37. void f_i8_arg(i8_mode_t* x) { (void)x; }
  38. void f_ui8_arg(ui8_mode_t* x) { (void)x; }
  39. void f_i16_arg(i16_mode_t* x) { (void)x; }
  40. void f_ui16_arg(ui16_mode_t* x) { (void)x; }
  41. void f_i32_arg(i32_mode_t* x) { (void)x; }
  42. void f_ui32_arg(ui32_mode_t* x) { (void)x; }
  43. void f_i64_arg(i64_mode_t* x) { (void)x; }
  44. void f_ui64_arg(ui64_mode_t* x) { (void)x; }
  45. void test_char_to_i8(signed char* y) { f_i8_arg(y); }
  46. void test_char_to_ui8(unsigned char* y) { f_ui8_arg(y); }
  47. void test_short_to_i16(short* y) { f_i16_arg(y); }
  48. void test_short_to_ui16(unsigned short* y) { f_ui16_arg(y); }
  49. void test_int_to_i32(int* y) { f_i32_arg(y); }
  50. void test_int_to_ui32(unsigned int* y) { f_ui32_arg(y); }
  51. #if TEST_32BIT_X86
  52. void test_long_to_i64(long long* y) { f_i64_arg(y); }
  53. void test_long_to_ui64(unsigned long long* y) { f_ui64_arg(y); }
  54. #elif TEST_64BIT_X86
  55. void test_long_to_i64(long* y) { f_i64_arg(y); }
  56. void test_long_to_ui64(unsigned long* y) { f_ui64_arg(y); }
  57. typedef float f128ibm __attribute__ ((mode (TF))); // expected-error{{unsupported machine mode 'TF'}}
  58. #elif TEST_64BIT_PPC64
  59. typedef float f128ibm __attribute__ ((mode (TF)));
  60. typedef _Complex float c128ibm __attribute__ ((mode (TC)));
  61. void f_ft128_arg(long double *x);
  62. void f_ft128_complex_arg(_Complex long double *x);
  63. void test_TFtype(f128ibm *a) { f_ft128_arg (a); }
  64. void test_TCtype(c128ibm *a) { f_ft128_complex_arg (a); }
  65. #else
  66. #error Unknown test architecture.
  67. #endif