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 // RUN: %clang_cc1 -triple powerpc64-pc-linux-gnu -DTEST_F128_PPC64 -fsyntax-only \
8 // RUN:   -verify -target-feature +float128 %s
9 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnux32 -DTEST_64BIT_X86 -fsyntax-only \
10 // RUN:   -verify %s
11 // RUN: %clang_cc1 -triple mips-linux-gnu -DTEST_MIPS_32 -fsyntax-only \
12 // RUN:   -verify %s
13 // RUN: %clang_cc1 -triple mips64-linux-gnuabin32 -DTEST_MIPS_N32 -fsyntax-only \
14 // RUN:   -verify %s
15 // RUN: %clang_cc1 -triple mips64-linux-gnu -DTEST_MIPS_64 -fsyntax-only \
16 // RUN:   -verify %s
17 
18 typedef int i16_1 __attribute((mode(HI)));
19 int i16_1_test[sizeof(i16_1) == 2 ? 1 : -1];
20 typedef int i16_2 __attribute((__mode__(__HI__)));
21 int i16_2_test[sizeof(i16_1) == 2 ? 1 : -1];
22 
23 typedef float f64 __attribute((mode(DF)));
24 int f64_test[sizeof(f64) == 8 ? 1 : -1];
25 
26 typedef int invalid_1 __attribute((mode)); // expected-error{{'mode' attribute takes one argument}}
27 typedef int invalid_2 __attribute((mode())); // expected-error{{'mode' attribute takes one argument}}
28 typedef int invalid_3 __attribute((mode(II))); // expected-error{{unknown machine mode}}
29 typedef struct {int i,j,k;} invalid_4 __attribute((mode(SI))); // expected-error{{mode attribute only supported for integer and floating-point types}}
30 typedef float invalid_5 __attribute((mode(SI))); // expected-error{{type of machine mode does not match type of base type}}
31 typedef int invalid_6 __attribute__((mode(12)));  // expected-error{{'mode' attribute requires an identifier}}
32 
33 typedef unsigned unwind_word __attribute((mode(unwind_word)));
34 
35 int **__attribute((mode(QI)))* i32;  // expected-error{{mode attribute}}
36 
invalid_func()37 __attribute__((mode(QI))) int invalid_func() { return 1; } // expected-error{{'mode' attribute only applies to variables, enums, typedefs, and non-static data members}}
38 enum invalid_enum { A1 __attribute__((mode(QI))) }; // expected-error{{'mode' attribute only applies to}}
39 
40 typedef _Complex double c32 __attribute((mode(SC)));
41 int c32_test[sizeof(c32) == 8 ? 1 : -1];
42 typedef _Complex float c64 __attribute((mode(DC)));
43 
44 #if !defined(__ppc__) && !defined(__mips__) // Note, 'XC' mode is illegal for PPC64 and MIPS machines.
45 typedef _Complex float c80 __attribute((mode(XC)));
46 #endif
47 
48 // PR6108: Correctly select 'long' built in type on 64-bit platforms for 64 bit
49 // modes. Also test other mode-based conversions.
50 typedef int i8_mode_t __attribute__ ((__mode__ (__QI__)));
51 typedef unsigned int ui8_mode_t __attribute__ ((__mode__ (__QI__)));
52 typedef int i16_mode_t __attribute__ ((__mode__ (__HI__)));
53 typedef unsigned int ui16_mode_t __attribute__ ((__mode__ (__HI__)));
54 typedef int i32_mode_t __attribute__ ((__mode__ (__SI__)));
55 typedef unsigned int ui32_mode_t __attribute__ ((__mode__ (__SI__)));
56 typedef int i64_mode_t __attribute__ ((__mode__ (__DI__)));
57 typedef unsigned int ui64_mode_t __attribute__ ((__mode__ (__DI__)));
f_i8_arg(i8_mode_t * x)58 void f_i8_arg(i8_mode_t* x) { (void)x; }
f_ui8_arg(ui8_mode_t * x)59 void f_ui8_arg(ui8_mode_t* x) { (void)x; }
f_i16_arg(i16_mode_t * x)60 void f_i16_arg(i16_mode_t* x) { (void)x; }
f_ui16_arg(ui16_mode_t * x)61 void f_ui16_arg(ui16_mode_t* x) { (void)x; }
f_i32_arg(i32_mode_t * x)62 void f_i32_arg(i32_mode_t* x) { (void)x; }
f_ui32_arg(ui32_mode_t * x)63 void f_ui32_arg(ui32_mode_t* x) { (void)x; }
f_i64_arg(i64_mode_t * x)64 void f_i64_arg(i64_mode_t* x) { (void)x; }
f_ui64_arg(ui64_mode_t * x)65 void f_ui64_arg(ui64_mode_t* x) { (void)x; }
test_char_to_i8(signed char * y)66 void test_char_to_i8(signed char* y) { f_i8_arg(y); }
test_char_to_ui8(unsigned char * y)67 void test_char_to_ui8(unsigned char* y) { f_ui8_arg(y); }
test_short_to_i16(short * y)68 void test_short_to_i16(short* y) { f_i16_arg(y); }
test_short_to_ui16(unsigned short * y)69 void test_short_to_ui16(unsigned short* y) { f_ui16_arg(y); }
test_int_to_i32(int * y)70 void test_int_to_i32(int* y) { f_i32_arg(y); }
test_int_to_ui32(unsigned int * y)71 void test_int_to_ui32(unsigned int* y) { f_ui32_arg(y); }
72 #if TEST_32BIT_X86
test_long_to_i64(long long * y)73 void test_long_to_i64(long long* y) { f_i64_arg(y); }
test_long_to_ui64(unsigned long long * y)74 void test_long_to_ui64(unsigned long long* y) { f_ui64_arg(y); }
75 #elif TEST_64BIT_X86
76 #ifdef __ILP32__
77 typedef unsigned int gcc_word __attribute__((mode(word)));
78 int foo[sizeof(gcc_word) == 8 ? 1 : -1];
79 typedef unsigned int gcc_unwind_word __attribute__((mode(unwind_word)));
80 int foo[sizeof(gcc_unwind_word) == 8 ? 1 : -1];
test_long_to_i64(long long * y)81 void test_long_to_i64(long long* y) { f_i64_arg(y); }
test_long_to_ui64(unsigned long long * y)82 void test_long_to_ui64(unsigned long long* y) { f_ui64_arg(y); }
83 #else
test_long_to_i64(long * y)84 void test_long_to_i64(long* y) { f_i64_arg(y); }
test_long_to_ui64(unsigned long * y)85 void test_long_to_ui64(unsigned long* y) { f_ui64_arg(y); }
86 #endif
87 typedef          float f128ibm __attribute__ ((mode (TF)));
88 #elif TEST_64BIT_PPC64
89 typedef          float f128ibm __attribute__ ((mode (TF)));
90 typedef _Complex float c128ibm __attribute__ ((mode (TC)));
91 void f_ft128_arg(long double *x);
92 void f_ft128_complex_arg(_Complex long double *x);
test_TFtype(f128ibm * a)93 void test_TFtype(f128ibm *a) { f_ft128_arg (a); }
test_TCtype(c128ibm * a)94 void test_TCtype(c128ibm *a) { f_ft128_complex_arg (a); }
95 #elif TEST_F128_PPC64
96 typedef int invalid_7 __attribute((mode(KF))); // expected-error{{type of machine mode does not match type of base type}}
97 typedef int invalid_8 __attribute((mode(KI))); // expected-error{{unknown machine mode}}
98 typedef _Complex float cf128 __attribute__((mode(KC)));
99 typedef float f128 __attribute__((mode(KF)));
100 void f_f128_arg(__float128 *x);
101 void f_f128_complex_arg(_Complex __float128 *x);
test_KFtype(f128 * a)102 void test_KFtype(f128 *a) { f_f128_arg(a); }
test_KCtype(cf128 * a)103 void test_KCtype(cf128 *a) { f_f128_complex_arg(a); }
104 #elif TEST_MIPS_32
105 typedef unsigned int gcc_unwind_word __attribute__((mode(unwind_word)));
106 int foo[sizeof(gcc_unwind_word) == 4 ? 1 : -1];
107 #elif TEST_MIPS_N32
108 typedef unsigned int gcc_unwind_word __attribute__((mode(unwind_word)));
109 int foo[sizeof(gcc_unwind_word) == 8 ? 1 : -1];
110 #elif TEST_MIPS_64
111 typedef unsigned int gcc_unwind_word __attribute__((mode(unwind_word)));
112 int foo[sizeof(gcc_unwind_word) == 8 ? 1 : -1];
113 #else
114 #error Unknown test architecture.
115 #endif
116 
117 struct S {
118   int n __attribute((mode(HI)));
119 };
120