Home | History | Annotate | Download | only in Sema
      1 // RUN: %clang_cc1 -fsyntax-only -verify %s
      2 
      3 // Math stuff
      4 
      5 double       g0  = __builtin_huge_val();
      6 float        g1  = __builtin_huge_valf();
      7 long double  g2  = __builtin_huge_vall();
      8 
      9 double       g3  = __builtin_inf();
     10 float        g4  = __builtin_inff();
     11 long double  g5  = __builtin_infl();
     12 
     13 double       g6  = __builtin_nan("");
     14 float        g7  = __builtin_nanf("");
     15 long double  g8  = __builtin_nanl("");
     16 
     17 // GCC constant folds these too (via native strtol):
     18 //double       g6_1  = __builtin_nan("1");
     19 //float        g7_1  = __builtin_nanf("1");
     20 //long double  g8_1  = __builtin_nanl("1");
     21 
     22 // APFloat doesn't have signalling NaN functions.
     23 //double       g9  = __builtin_nans("");
     24 //float        g10 = __builtin_nansf("");
     25 //long double  g11 = __builtin_nansl("");
     26 
     27 //int          g12 = __builtin_abs(-12);
     28 
     29 double       g13 = __builtin_fabs(-12.);
     30 double       g13_0 = __builtin_fabs(-0.);
     31 double       g13_1 = __builtin_fabs(-__builtin_inf());
     32 float        g14 = __builtin_fabsf(-12.f);
     33 // GCC doesn't eat this one.
     34 //long double  g15 = __builtin_fabsfl(-12.0L);
     35 
     36 float        g16 = __builtin_copysign(1.0, -1.0);
     37 double       g17 = __builtin_copysignf(1.0f, -1.0f);
     38 long double  g18 = __builtin_copysignl(1.0L, -1.0L);
     39 
     40 char classify_nan     [__builtin_fpclassify(+1, -1, -1, -1, -1, __builtin_nan(""))];
     41 char classify_snan    [__builtin_fpclassify(+1, -1, -1, -1, -1, __builtin_nans(""))];
     42 char classify_inf     [__builtin_fpclassify(-1, +1, -1, -1, -1, __builtin_inf())];
     43 char classify_neg_inf [__builtin_fpclassify(-1, +1, -1, -1, -1, -__builtin_inf())];
     44 char classify_normal  [__builtin_fpclassify(-1, -1, +1, -1, -1, 1.539)];
     45 char classify_normal2 [__builtin_fpclassify(-1, -1, +1, -1, -1, 1e-307)];
     46 char classify_denorm  [__builtin_fpclassify(-1, -1, -1, +1, -1, 1e-308)];
     47 char classify_denorm2 [__builtin_fpclassify(-1, -1, -1, +1, -1, -1e-308)];
     48 char classify_zero    [__builtin_fpclassify(-1, -1, -1, -1, +1, 0.0)];
     49 char classify_neg_zero[__builtin_fpclassify(-1, -1, -1, -1, +1, -0.0)];
     50 
     51 char isinf_sign_noninf1[__builtin_isinf_sign(-0.0) == 0 ? 1 : -1];
     52 char isinf_sign_noninf2[__builtin_isinf_sign(1e307) == 0 ? 1 : -1];
     53 char isinf_sign_noninf3[__builtin_isinf_sign(__builtin_nan("")) == 0 ? 1 : -1];
     54 char isinf_sign_noninf4[__builtin_isinf_sign(-436.) == 0 ? 1 : -1];
     55 char isinf_sign_inf    [__builtin_isinf_sign(__builtin_inf()) == 1 ? 1 : -1];
     56 char isinf_sign_neg_inf[__builtin_isinf_sign(-__builtin_inf()) == -1 ? 1 : -1];
     57 
     58 //double       g19 = __builtin_powi(2.0, 4);
     59 //float        g20 = __builtin_powif(2.0f, 4);
     60 //long double  g21 = __builtin_powil(2.0L, 4);
     61 
     62 #define BITSIZE(x) (sizeof(x) * 8)
     63 char g22[__builtin_clz(1) == BITSIZE(int) - 1 ? 1 : -1];
     64 char g23[__builtin_clz(7) == BITSIZE(int) - 3 ? 1 : -1];
     65 char g24[__builtin_clz(1 << (BITSIZE(int) - 1)) == 0 ? 1 : -1];
     66 int g25 = __builtin_clz(0); // expected-error {{not a compile-time constant}}
     67 char g26[__builtin_clzl(0xFL) == BITSIZE(long) - 4 ? 1 : -1];
     68 char g27[__builtin_clzll(0xFFLL) == BITSIZE(long long) - 8 ? 1 : -1];
     69 
     70 char g28[__builtin_ctz(1) == 0 ? 1 : -1];
     71 char g29[__builtin_ctz(8) == 3 ? 1 : -1];
     72 char g30[__builtin_ctz(1 << (BITSIZE(int) - 1)) == BITSIZE(int) - 1 ? 1 : -1];
     73 int g31 = __builtin_ctz(0); // expected-error {{not a compile-time constant}}
     74 char g32[__builtin_ctzl(0x10L) == 4 ? 1 : -1];
     75 char g33[__builtin_ctzll(0x100LL) == 8 ? 1 : -1];
     76 
     77 char g34[__builtin_popcount(0) == 0 ? 1 : -1];
     78 char g35[__builtin_popcount(0xF0F0) == 8 ? 1 : -1];
     79 char g36[__builtin_popcount(~0) == BITSIZE(int) ? 1 : -1];
     80 char g37[__builtin_popcount(~0L) == BITSIZE(int) ? 1 : -1];
     81 char g38[__builtin_popcountl(0L) == 0 ? 1 : -1];
     82 char g39[__builtin_popcountl(0xF0F0L) == 8 ? 1 : -1];
     83 char g40[__builtin_popcountl(~0L) == BITSIZE(long) ? 1 : -1];
     84 char g41[__builtin_popcountll(0LL) == 0 ? 1 : -1];
     85 char g42[__builtin_popcountll(0xF0F0LL) == 8 ? 1 : -1];
     86 char g43[__builtin_popcountll(~0LL) == BITSIZE(long long) ? 1 : -1];
     87 
     88 char g44[__builtin_parity(0) == 0 ? 1 : -1];
     89 char g45[__builtin_parity(0xb821) == 0 ? 1 : -1];
     90 char g46[__builtin_parity(0xb822) == 0 ? 1 : -1];
     91 char g47[__builtin_parity(0xb823) == 1 ? 1 : -1];
     92 char g48[__builtin_parity(0xb824) == 0 ? 1 : -1];
     93 char g49[__builtin_parity(0xb825) == 1 ? 1 : -1];
     94 char g50[__builtin_parity(0xb826) == 1 ? 1 : -1];
     95 char g51[__builtin_parity(~0) == 0 ? 1 : -1];
     96 char g52[__builtin_parityl(1L << (BITSIZE(long) - 1)) == 1 ? 1 : -1];
     97 char g53[__builtin_parityll(1LL << (BITSIZE(long long) - 1)) == 1 ? 1 : -1];
     98 
     99 char g54[__builtin_ffs(0) == 0 ? 1 : -1];
    100 char g55[__builtin_ffs(1) == 1 ? 1 : -1];
    101 char g56[__builtin_ffs(0xfbe71) == 1 ? 1 : -1];
    102 char g57[__builtin_ffs(0xfbe70) == 5 ? 1 : -1];
    103 char g58[__builtin_ffs(1U << (BITSIZE(int) - 1)) == BITSIZE(int) ? 1 : -1];
    104 char g59[__builtin_ffsl(0x10L) == 5 ? 1 : -1];
    105 char g60[__builtin_ffsll(0x100LL) == 9 ? 1 : -1];
    106 #undef BITSIZE
    107 
    108 // GCC misc stuff
    109 
    110 extern int f();
    111 
    112 int h0 = __builtin_types_compatible_p(int, float);
    113 //int h1 = __builtin_choose_expr(1, 10, f());
    114 //int h2 = __builtin_expect(0, 0);
    115 int h3 = __builtin_bswap16(0x1234) == 0x3412 ? 1 : f();
    116 int h4 = __builtin_bswap32(0x1234) == 0x34120000 ? 1 : f();
    117 int h5 = __builtin_bswap64(0x1234) == 0x3412000000000000 ? 1 : f();
    118 extern long int bi0;
    119 extern __typeof__(__builtin_expect(0, 0)) bi0;
    120 
    121 // Strings
    122 int array1[__builtin_strlen("ab\0cd")];
    123 int array2[(sizeof(array1)/sizeof(int)) == 2? 1 : -1];
    124