1 // RUN: %clang_cc1 -fsyntax-only %s -verify -pedantic -std=c99
2 // RUN: %clang_cc1 -fsyntax-only %s -verify -pedantic -std=c11
3 // RUN: %clang_cc1 -fsyntax-only %s -verify -pedantic -std=c17
4 // RUN: %clang_cc1 -fsyntax-only %s -verify -pedantic
5 #if __STDC_VERSION__ >= 201112L
6 // expected-no-diagnostics
7 #endif
8 
9 // Math stuff
10 
11 float        g0 = __builtin_huge_val();
12 double       g1 = __builtin_huge_valf();
13 long double  g2 = __builtin_huge_vall();
14 float        g3 = __builtin_inf();
15 double       g4 = __builtin_inff();
16 long double  g5 = __builtin_infl();
17 
18 // GCC misc stuff
19 
20 extern int f();
21 
22 int h0 = __builtin_types_compatible_p(int,float);
23 //int h1 = __builtin_choose_expr(1, 10, f());
24 //int h2 = __builtin_expect(0, 0);
25 int h3 = __builtin_bswap16(0x1234) == 0x3412 ? 1 : f();
26 int h4 = __builtin_bswap32(0x1234) == 0x34120000 ? 1 : f();
27 int h5 = __builtin_bswap64(0x1234) == 0x3412000000000000 ? 1 : f();
28 
29 short somefunc();
30 
31 short t = __builtin_constant_p(5353) ? 42 : somefunc();
32 
33 // The calls to _Static_assert and _Generic produce warnings if the compiler default standard is < c11
34 #if __STDC_VERSION__ < 201112L
35 // expected-warning@+9 {{'_Static_assert' is a C11 extension}}
36 // expected-warning@+9 {{'_Static_assert' is a C11 extension}}
37 // expected-warning@+9 {{'_Static_assert' is a C11 extension}}
38 // expected-warning@+9 {{'_Static_assert' is a C11 extension}} expected-warning@+9 {{'_Generic' is a C11 extension}}
39 // expected-warning@+9 {{'_Static_assert' is a C11 extension}} expected-warning@+9 {{'_Generic' is a C11 extension}}
40 // expected-warning@+9 {{'_Static_assert' is a C11 extension}} expected-warning@+9 {{'_Generic' is a C11 extension}}
41 #endif
42 
43 // PR44684
44 _Static_assert((__builtin_clz)(1u) >= 15, "");
45 _Static_assert((__builtin_popcount)(1u) == 1, "");
46 _Static_assert((__builtin_ctz)(2u) == 1, "");
47 _Static_assert(_Generic(1u,unsigned:__builtin_clz)(1u) >= 15, "");
48 _Static_assert(_Generic(1u,unsigned:__builtin_popcount)(1u) == 1, "");
49 _Static_assert(_Generic(1u,unsigned:__builtin_ctz)(2u) == 1, "");
50 
51 #if __STDC_VERSION__ < 201112L
52 // expected-warning@+3 {{'_Static_assert' is a C11 extension}}
53 #endif
54 __SIZE_TYPE__ strlen(const char*);
55 _Static_assert((__builtin_constant_p(1) ? (***&strlen)("foo") : 0) == 3, "");
56