Debian Codegraph @

clang/test/Sema/constant-builtins.c

raw
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(void);
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 int h6 = __builtin_bswapg((char)0x12) == (char)0x12 ? 1 : f();
29 int h7 = __builtin_bswapg((short)(0x1234)) == (short)(0x3412) ? 1 : f();
30 int h8 = __builtin_bswapg(0x00001234) == 0x34120000 ? 1 : f();
31 int h9 = __builtin_bswapg(0x0000000000001234ULL) == 0x3412000000000000 ? 1 : f();
32 short somefunc(void);
33
34 short t = __builtin_constant_p(5353) ? 42 : somefunc();
35
36 // The calls to _Static_assert and _Generic produce warnings if the compiler default standard is < c11
37 #if __STDC_VERSION__ < 201112L
38 // expected-warning@+9 {{'_Static_assert' is a C11 extension}}
39 // expected-warning@+9 {{'_Static_assert' is a C11 extension}}
40 // expected-warning@+9 {{'_Static_assert' is a C11 extension}}
41 // expected-warning@+9 {{'_Static_assert' is a C11 extension}} expected-warning@+9 {{'_Generic' is a C11 extension}}
42 // expected-warning@+9 {{'_Static_assert' is a C11 extension}} expected-warning@+9 {{'_Generic' is a C11 extension}}
43 // expected-warning@+9 {{'_Static_assert' is a C11 extension}} expected-warning@+9 {{'_Generic' is a C11 extension}}
44 #endif
45
46 // PR44684
47 _Static_assert((__builtin_clz)(1u) >= 15, "");
48 _Static_assert((__builtin_popcount)(1u) == 1, "");
49 _Static_assert((__builtin_ctz)(2u) == 1, "");
50 _Static_assert(_Generic(1u,unsigned:__builtin_clz)(1u) >= 15, "");
51 _Static_assert(_Generic(1u,unsigned:__builtin_popcount)(1u) == 1, "");
52 _Static_assert(_Generic(1u,unsigned:__builtin_ctz)(2u) == 1, "");
53
54 #if __STDC_VERSION__ < 201112L
55 // expected-warning@+3 {{'_Static_assert' is a C11 extension}}
56 #endif
57 __SIZE_TYPE__ strlen(const char*);
58 _Static_assert((__builtin_constant_p(1) ? (***&strlen)("foo") : 0) == 3, "");