Debian Codegraph @

clang/test/CodeGenCXX/builtin-constant-p.cpp

raw
1 // RUN: %clang_cc1 -triple=x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s
2 // RUN: %clang_cc1 -triple=x86_64-linux-gnu -emit-llvm -o - %s -fexperimental-new-constant-interpreter | FileCheck %s
3
4 // Don't crash if the argument to __builtin_constant_p isn't scalar.
5 template <typename T>
6 constexpr bool is_constant(const T v) {
7 return __builtin_constant_p(v);
8 }
9
10 template <typename T>
11 class numeric {
12 public:
13 using type = T;
14
15 template <typename S>
16 constexpr numeric(S value)
17 : value_(static_cast<T>(value)) {}
18
19 private:
20 const T value_;
21 };
22
23 bool bcp() {
24 return is_constant(numeric<int>(1));
25 }
26
27 // PR45535
28 struct with_dtor {
29 ~with_dtor();
30 };
31 // CHECK: define {{.*}}bcp_stmt_expr_1
32 bool bcp_stmt_expr_1() {
33 // CHECK-NOT: call {{.*}}with_dtorD
34 return __builtin_constant_p(({with_dtor wd; 123;}));
35 }
36
37 int do_not_call();
38 // CHECK: define {{.*}}bcp_stmt_expr_2
39 bool bcp_stmt_expr_2(int n) {
40 // CHECK-NOT: call {{.*}}do_not_call
41 return __builtin_constant_p(({
42 // This has a side-effect due to the VLA bound, so CodeGen should fold it
43 // to false.
44 typedef int arr[do_not_call()];
45 n;
46 }));
47 // CHECK-NOT: }
48 // CHECK: ret i1 false
49 }