131 lines · c
1// RUN: %clang_cc1 -triple i686-pc-linux-gnu -DTEST_32BIT_X86 -fsyntax-only \2// RUN: -verify %s3// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -DTEST_64BIT_X86 -fsyntax-only \4// RUN: -verify %s5// RUN: %clang_cc1 -triple powerpc64-pc-linux-gnu -DTEST_64BIT_PPC64 -fsyntax-only \6// RUN: -verify %s7// RUN: %clang_cc1 -triple powerpc64-pc-linux-gnu -DTEST_F128_PPC64 -fsyntax-only \8// RUN: -verify -target-feature +float128 %s9// RUN: %clang_cc1 -triple x86_64-pc-linux-gnux32 -DTEST_64BIT_X86 -fsyntax-only \10// RUN: -verify %s11// RUN: %clang_cc1 -triple mips-linux-gnu -DTEST_MIPS_32 -fsyntax-only \12// RUN: -verify %s13// RUN: %clang_cc1 -triple mips64-linux-gnuabin32 -DTEST_MIPS_N32 -fsyntax-only \14// RUN: -verify %s15// RUN: %clang_cc1 -triple mips64-linux-gnu -DTEST_MIPS_64 -fsyntax-only \16// RUN: -verify %s17 18typedef int i16_1 __attribute((mode(HI)));19int i16_1_test[sizeof(i16_1) == 2 ? 1 : -1];20typedef int i16_2 __attribute((__mode__(__HI__)));21int i16_2_test[sizeof(i16_1) == 2 ? 1 : -1];22 23typedef float f64 __attribute((mode(DF)));24int f64_test[sizeof(f64) == 8 ? 1 : -1];25 26typedef int invalid_1 __attribute((mode)); // expected-error{{'mode' attribute takes one argument}}27typedef int invalid_2 __attribute((mode())); // expected-error{{'mode' attribute takes one argument}}28typedef int invalid_3 __attribute((mode(II))); // expected-error{{unknown machine mode}}29typedef struct {int i,j,k;} invalid_4 __attribute((mode(SI))); // expected-error{{mode attribute only supported for integer and floating-point types}}30typedef float invalid_5 __attribute((mode(SI))); // expected-error{{type of machine mode does not match type of base type}}31typedef int invalid_6 __attribute__((mode(12))); // expected-error{{'mode' attribute requires an identifier}}32 33typedef unsigned unwind_word __attribute((mode(unwind_word)));34 35int **__attribute((mode(QI)))* i32; // expected-error{{mode attribute}}36 37__attribute__((mode(QI))) int invalid_func(void) { return 1; } // expected-error{{'mode' attribute only applies to variables, enums, typedefs, and non-static data members}}38enum invalid_enum { A1 __attribute__((mode(QI))) }; // expected-error{{'mode' attribute only applies to}}39 40typedef _Complex float c16a __attribute((mode(HC)));41int c16a_test[sizeof(c16a) == 4 ? 1 : -1];42typedef _Complex double c16b __attribute((mode(HC)));43int c16b_test[sizeof(c16b) == 4 ? 1 : -1];44 45typedef _Complex double c32 __attribute((mode(SC)));46int c32_test[sizeof(c32) == 8 ? 1 : -1];47typedef _Complex float c64 __attribute((mode(DC)));48 49#if !defined(__powerpc__) && !defined(__mips__) // Note, 'XC' mode is illegal for PPC64 and MIPS machines.50typedef _Complex float c80 __attribute((mode(XC)));51#endif52 53// PR6108: Correctly select 'long' built in type on 64-bit platforms for 64 bit54// modes. Also test other mode-based conversions.55typedef int i8_mode_t __attribute__ ((__mode__ (__QI__)));56typedef unsigned int ui8_mode_t __attribute__ ((__mode__ (__QI__)));57typedef int i16_mode_t __attribute__ ((__mode__ (__HI__)));58typedef unsigned int ui16_mode_t __attribute__ ((__mode__ (__HI__)));59typedef int i32_mode_t __attribute__ ((__mode__ (__SI__)));60typedef unsigned int ui32_mode_t __attribute__ ((__mode__ (__SI__)));61typedef int i64_mode_t __attribute__ ((__mode__ (__DI__)));62typedef unsigned int ui64_mode_t __attribute__ ((__mode__ (__DI__)));63void f_i8_arg(i8_mode_t* x) { (void)x; }64void f_ui8_arg(ui8_mode_t* x) { (void)x; }65void f_i16_arg(i16_mode_t* x) { (void)x; }66void f_ui16_arg(ui16_mode_t* x) { (void)x; }67void f_i32_arg(i32_mode_t* x) { (void)x; }68void f_ui32_arg(ui32_mode_t* x) { (void)x; }69void f_i64_arg(i64_mode_t* x) { (void)x; }70void f_ui64_arg(ui64_mode_t* x) { (void)x; }71void test_char_to_i8(signed char* y) { f_i8_arg(y); }72void test_char_to_ui8(unsigned char* y) { f_ui8_arg(y); }73void test_short_to_i16(short* y) { f_i16_arg(y); }74void test_short_to_ui16(unsigned short* y) { f_ui16_arg(y); }75void test_int_to_i32(int* y) { f_i32_arg(y); }76void test_int_to_ui32(unsigned int* y) { f_ui32_arg(y); }77#if TEST_32BIT_X8678void test_long_to_i64(long long* y) { f_i64_arg(y); }79void test_long_to_ui64(unsigned long long* y) { f_ui64_arg(y); }80#elif TEST_64BIT_X8681#ifdef __ILP32__82typedef unsigned int gcc_word __attribute__((mode(word)));83int foo[sizeof(gcc_word) == 8 ? 1 : -1];84typedef unsigned int gcc_unwind_word __attribute__((mode(unwind_word)));85int foo[sizeof(gcc_unwind_word) == 8 ? 1 : -1];86void test_long_to_i64(long long* y) { f_i64_arg(y); }87void test_long_to_ui64(unsigned long long* y) { f_ui64_arg(y); }88#else89void test_long_to_i64(long* y) { f_i64_arg(y); }90void test_long_to_ui64(unsigned long* y) { f_ui64_arg(y); }91#endif92typedef float f128ibm __attribute__ ((mode (TF)));93#elif TEST_64BIT_PPC6494typedef float f128ibm __attribute__ ((mode (TF)));95typedef _Complex float c128ibm __attribute__ ((mode (TC)));96void f_ft128_arg(long double *x);97void f_ft128_complex_arg(_Complex long double *x);98void test_TFtype(f128ibm *a) { f_ft128_arg (a); }99void test_TCtype(c128ibm *a) { f_ft128_complex_arg (a); }100typedef float w128ibm __attribute__((mode(IF)));101typedef _Complex float cw128ibm __attribute__((mode(IC)));102void f_ibm128_arg(__ibm128 *x);103void f_ibm128_complex_arg(_Complex __ibm128 *x);104void test_IFtype(w128ibm *a) { f_ibm128_arg(a); }105void test_ICtype(cw128ibm *a) { f_ibm128_complex_arg(a); }106#elif TEST_F128_PPC64107typedef int invalid_7 __attribute((mode(KF))); // expected-error{{type of machine mode does not match type of base type}}108typedef int invalid_8 __attribute((mode(KI))); // expected-error{{unknown machine mode}}109typedef _Complex float cf128 __attribute__((mode(KC)));110typedef float f128 __attribute__((mode(KF)));111void f_f128_arg(__float128 *x);112void f_f128_complex_arg(_Complex __float128 *x);113void test_KFtype(f128 *a) { f_f128_arg(a); }114void test_KCtype(cf128 *a) { f_f128_complex_arg(a); }115#elif TEST_MIPS_32116typedef unsigned int gcc_unwind_word __attribute__((mode(unwind_word)));117int foo[sizeof(gcc_unwind_word) == 4 ? 1 : -1];118#elif TEST_MIPS_N32119typedef unsigned int gcc_unwind_word __attribute__((mode(unwind_word)));120int foo[sizeof(gcc_unwind_word) == 8 ? 1 : -1];121#elif TEST_MIPS_64122typedef unsigned int gcc_unwind_word __attribute__((mode(unwind_word)));123int foo[sizeof(gcc_unwind_word) == 8 ? 1 : -1];124#else125#error Unknown test architecture.126#endif127 128struct S {129 int n __attribute((mode(HI)));130};131