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