1 // RUN: %clang_cc1 -std=c++98 -Wno-constant-evaluated -triple x86_64-linux -include %s -verify %s -emit-llvm -o - | FileCheck %s
2 // RUN: %clang_cc1 -std=c++98 -Wno-constant-evaluated -triple x86_64-linux -emit-pch %s -o %t
3 // RUN: %clang_cc1 -std=c++98 -Wno-constant-evaluated -triple x86_64-linux -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
4 
5 // RUN: %clang_cc1 -std=c++11 -Wno-constant-evaluated -triple x86_64-linux -include %s -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CXX11
6 // RUN: %clang_cc1 -std=c++11 -Wno-constant-evaluated -triple x86_64-linux -emit-pch %s -o %t-cxx11
7 // RUN: %clang_cc1 -std=c++11 -Wno-constant-evaluated -triple x86_64-linux -include-pch %t-cxx11 -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CXX11
8 
9 // RUN: %clang_cc1 -std=c++20 -Wno-constant-evaluated -triple x86_64-linux -include %s -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CXX11
10 // RUN: %clang_cc1 -std=c++20 -Wno-constant-evaluated -triple x86_64-linux -emit-pch %s -o %t-cxx11
11 // RUN: %clang_cc1 -std=c++20 -Wno-constant-evaluated -triple x86_64-linux -include-pch %t-cxx11 -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CXX11
12 
13 // expected-no-diagnostics
14 
15 #ifndef HEADER_INCLUDED
16 #define HEADER_INCLUDED
17 
18 // CHECK-DAG: @a = global i8 1,
19 // CHECK-DAG: @b = constant i8 1,
20 // CXX11-DAG: @c = constant i8 1,
21 // CHECK-DAG: @d = global float 1.000000e+00
22 // CHECK-DAG: @e = constant float 1.000000e+00
23 
24 bool a = __builtin_is_constant_evaluated();
25 extern const bool b = __builtin_is_constant_evaluated();
26 #if __cplusplus >= 201103L
27 extern constexpr bool c = __builtin_is_constant_evaluated();
28 #endif
29 float d = __builtin_is_constant_evaluated();
30 extern const float e = __builtin_is_constant_evaluated();
31 
32 void g(...);
33 
34 // CHECK-LABEL: define {{.*}} @_Z1fv(
35 // CHECK:       store i8 0, i8* %[[A:.*]],
36 // CHECK:       store i8 1, i8* %[[B:.*]],
37 // CXX11:       store i8 1, i8* %[[C:.*]],
38 // CHECK:       store float 0.000000e+00, float* %[[D:.*]],
39 // CHECK:       store float 0.000000e+00, float* %[[E:.*]],
40 // CHECK:       load i8, i8* %[[A]],
41 // CHECK:       call {{.*}} @_Z1gz(i32 %{{[^,]+}}, i32 1
42 // CXX11-SAME:  , i32 1
43 // CHECK-SAME:  , double %{{[^,]+}}, double 0.000000e+00)
f()44 void f() {
45   bool a = __builtin_is_constant_evaluated();
46   const bool b = __builtin_is_constant_evaluated();
47 #if __cplusplus >= 201103L
48   constexpr bool c = __builtin_is_constant_evaluated();
49 #endif
50   float d = __builtin_is_constant_evaluated();
51   const float e = __builtin_is_constant_evaluated();
52   g(a, b
53 #if __cplusplus >= 201103L
54       , c
55 #endif
56       , d, e);
57 }
58 
59 #else
60 
61 _Static_assert(b, "");
62 #if __cplusplus >= 201103L
63 static_assert(c, "");
64 #endif
65 _Static_assert(__builtin_constant_p(1) ? e == 1.0f : false, "");
66 
67 #endif
68