1 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 %s -emit-llvm -o - | FileCheck %s
2 // RUN: %clang_cc1 -emit-obj -debug-info-kind=constructor -std=c++20 %s -o -
5 // This code would previously cause a crash.
7 consteval
auto& X() { return x_
; }
8 constexpr auto& x1
= X();
11 // CHECK: @_ZN7PR507872x_E = external global i32, align 4
12 // CHECK-NEXT: @_ZN7PR507872x1E = constant ptr @_ZN7PR507872x_E, align 8
13 // CHECK-NEXT: @_ZN7PR507872x2E = global i32 0, align 4
17 // This code would previously cause a crash.
18 struct X
{ int val
; };
19 consteval X
g() { return {0}; }
22 // CHECK: define dso_local void @_ZN7PR514841fEv() #1 {
24 // CHECK-NOT: call i32 @_ZN7PR514841gEv()
29 namespace Issue54578
{
30 inline consteval
unsigned char operator""_UC(const unsigned long long n
) {
31 return static_cast<unsigned char>(n
);
34 inline constexpr char f1(const auto octet
) {
38 template <typename Ty
>
39 inline constexpr char f2(const Ty octet
) {
44 return f1('a') + f2('a');
47 // Because the consteval functions are inline (implicitly as well as
48 // explicitly), we need to defer the CHECK lines until this point to get the
49 // order correct. We want to ensure there is no definition of the consteval
50 // UDL function, and that the constexpr f1 and f2 functions both return a
53 // CHECK-NOT: define{{.*}} zeroext i8 @_ZN10Issue54578li3_UCEy
54 // CHECK: define{{.*}} i32 @_ZN10Issue545783fooEv(
55 // CHECK: define{{.*}} signext i8 @_ZN10Issue545782f1IcEEcT_(
57 // CHECK: define{{.*}} signext i8 @_ZN10Issue545782f2IcEEcT_(
61 namespace Issue55871
{
63 consteval
Item(char c
) :_char
{c
}{}
67 int function(const Item
& item1
, const Item
& item2
) {
72 return function(Item
{'a'}, Item
{'a'});
74 } // namespace Issue58871
76 namespace Issue55065
{
78 consteval
virtual int Get() const = 0;
81 struct Derived
: Base
{
82 consteval
int Get() const override
{
93 } // namespace Issue55065
102 struct Derived
: Base
{
103 void* three
= nullptr;
104 consteval
Derived() = default;
108 // CHECK: %agg.tmp.ensured = alloca %"struct.GH60166::Derived"
109 // CHECK: %0 = getelementptr inbounds nuw { ptr, ptr, ptr }, ptr %agg.tmp.ensured, i32 0, i32 0
110 // CHECK: store ptr null, ptr %0, align 8
111 // CHECK: %1 = getelementptr inbounds nuw { ptr, ptr, ptr }, ptr %agg.tmp.ensured, i32 0, i32 1
112 // CHECK: store ptr null, ptr %1, align 8
113 // CHECK: %2 = getelementptr inbounds nuw { ptr, ptr, ptr }, ptr %agg.tmp.ensured, i32 0, i32 2
114 // CHECK: store ptr null, ptr %2, align 8
118 } // namespace GH60166
122 template <typename T
>
124 constexpr static void bar() {
127 consteval
static void foo() {};
138 // Make sure consteval function is not emitted.
139 // CHECK-NOT: call {{.*}}foo{{.*}}()
140 // CHECK-NOT: define {{.*}}foo{{.*}}()
142 } // namespace GH61142