1 // RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-unknown-linux-gnu -std=c++20 %s -emit-llvm -o - | FileCheck %s
2 
3 namespace PR50787 {
4 // This code would previously cause a crash.
5 extern int x_;
X()6 consteval auto& X() { return x_; }
7 constexpr auto& x1 = X();
8 auto x2 = X();
9 
10 // CHECK: @_ZN7PR507872x_E = external global i32, align 4
11 // CHECK-NEXT: @_ZN7PR507872x1E = constant i32* @_ZN7PR507872x_E, align 8
12 // CHECK-NEXT: @_ZN7PR507872x2E = global i32 0, align 4
13 }
14 
15 namespace PR51484 {
16 // This code would previously cause a crash.
17 struct X { int val; };
g()18 consteval X g() { return {0}; }
f()19 void f() { g(); }
20 
21 // CHECK: define dso_local void @_ZN7PR514841fEv() #1 {
22 // CHECK: entry:
23 // CHECK-NOT: call i32 @_ZN7PR514841gEv()
24 // CHECK:  ret void
25 // CHECK: }
26 }
27 
28 namespace Issue54578 {
operator ""_UC(const unsigned long long n)29 inline consteval unsigned char operator""_UC(const unsigned long long n) {
30   return static_cast<unsigned char>(n);
31 }
32 
f1(const auto octet)33 inline constexpr char f1(const auto octet) {
34   return 4_UC;
35 }
36 
37 template <typename Ty>
f2(const Ty octet)38 inline constexpr char f2(const Ty octet) {
39   return 4_UC;
40 }
41 
foo()42 int foo() {
43   return f1('a') + f2('a');
44 }
45 
46 // Because the consteval functions are inline (implicitly as well as
47 // explicitly), we need to defer the CHECK lines until this point to get the
48 // order correct. We want to ensure there is no definition of the consteval
49 // UDL function, and that the constexpr f1 and f2 functions both return a
50 // constant value.
51 
52 // CHECK-NOT: define{{.*}} zeroext i8 @_ZN10Issue54578li3_UCEy
53 // CHECK: define{{.*}} i32 @_ZN10Issue545783fooEv(
54 // CHECK: define{{.*}} signext i8 @_ZN10Issue545782f1IcEEcT_(
55 // CHECK: ret i8 4
56 // CHECK: define{{.*}} signext i8 @_ZN10Issue545782f2IcEEcT_(
57 // CHECK: ret i8 4
58 }
59