1 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -disable-llvm-optzns -o - %s -O2 | FileCheck %s
2 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -disable-llvm-optzns -o - %s -O0 | FileCheck %s
6 /* --- Compound literals */
8 struct foo
{ int x
, y
; };
11 struct foo f
= (struct foo
){ __builtin_constant_p(y
), 42 };
13 struct foo
test0(int expr
) {
15 // CHECK: call i1 @llvm.is.constant.i32
16 struct foo f
= (struct foo
){ __builtin_constant_p(expr
), 42 };
20 /* --- Pointer types */
25 return __builtin_constant_p(&a
- 13);
28 /* --- Aggregate types */
35 return __builtin_constant_p(b
);
38 const char test3_c
[] = {1, 2, 3, 0};
43 return __builtin_constant_p(test3_c
);
46 inline char test4_i(const char *x
) {
51 // CHECK: define{{.*}} i32 @test4
53 return __builtin_constant_p(test4_i(test3_c
));
56 /* --- Constant global variables */
63 return __builtin_constant_p(c
);
68 int arr
[] = { 1, 2, 3 };
69 const int c_arr
[] = { 1, 2, 3 };
73 // CHECK: call i1 @llvm.is.constant.i32
74 return __builtin_constant_p(arr
[2]);
80 return __builtin_constant_p(c_arr
[2]);
86 return __builtin_constant_p(c_arr
);
89 /* --- Function pointers */
94 return __builtin_constant_p(&test9
);
98 // CHECK-LABEL: test10
100 return __builtin_constant_p(&test10
!= 0);
103 typedef unsigned long uintptr_t;
104 #define assign(p, v) ({ \
105 uintptr_t _r_a_p__v = (uintptr_t)(v); \
106 if (__builtin_constant_p(v) && _r_a_p__v == (uintptr_t)0) { \
111 .__val = (uintptr_t)_r_a_p__v \
113 *(volatile unsigned int*)&p = *(unsigned int*)(__u.__c); \
119 typedef void fn_p(void);
122 static void src_fn(void) {
126 assign(dest_p
, src_fn
);
131 struct { const char *t
; int a
; } test12
[] = {
132 { "tag", __builtin_constant_p(test12_v
) && !test12_v
? 1 : 0 }
135 extern char test13_v
;
136 struct { int a
; } test13
= { __builtin_constant_p(test13_v
) };
138 extern unsigned long long test14_v
;
141 // CHECK-LABEL: test14
142 // CHECK: call void asm sideeffect "", {{.*}}(i32 -1)
143 __asm__
__volatile__("" :: "n"( (__builtin_constant_p(test14_v
) || 0) ? 1 : -1));
147 // CHECK-LABEL: define{{.*}} void @test15
148 // CHECK-NOT: call {{.*}}test15_f
151 (void)__builtin_constant_p((a
= b
, test15_f()));