brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.3 KiB · 9c9324f Raw
143 lines · cpp
1// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 %s -emit-llvm -o - | FileCheck %s2// RUN: %clang_cc1 -emit-obj -debug-info-kind=constructor -std=c++20 %s -o -3 4namespace PR50787 {5// This code would previously cause a crash.6extern int x_;7consteval auto& X() { return x_; }8constexpr auto& x1 = X();9auto x2 = X();10 11// CHECK: @_ZN7PR507872x_E = external global i32, align 412// CHECK-NEXT: @_ZN7PR507872x1E = constant ptr @_ZN7PR507872x_E, align 813// CHECK-NEXT: @_ZN7PR507872x2E = global i32 0, align 414}15 16namespace PR51484 {17// This code would previously cause a crash.18struct X { int val; };19consteval X g() { return {0}; }20void f() { g(); }21 22// CHECK: define dso_local void @_ZN7PR514841fEv() #1 {23// CHECK: entry:24// CHECK-NOT: call i32 @_ZN7PR514841gEv()25// CHECK:  ret void26// CHECK: }27}28 29namespace Issue54578 {30inline consteval unsigned char operator""_UC(const unsigned long long n) {31  return static_cast<unsigned char>(n);32}33 34inline constexpr char f1(const auto octet) {35  return 4_UC;36}37 38template <typename Ty>39inline constexpr char f2(const Ty octet) {40  return 4_UC;41}42 43int foo() {44  return f1('a') + f2('a');45}46 47// Because the consteval functions are inline (implicitly as well as48// explicitly), we need to defer the CHECK lines until this point to get the49// order correct. We want to ensure there is no definition of the consteval50// UDL function, and that the constexpr f1 and f2 functions both return a51// constant value.52 53// CHECK-NOT: define{{.*}} zeroext i8 @_ZN10Issue54578li3_UCEy54// CHECK: define{{.*}} i32 @_ZN10Issue545783fooEv(55// CHECK: define{{.*}} signext i8 @_ZN10Issue545782f1IcEEcT_(56// CHECK: ret i8 457// CHECK: define{{.*}} signext i8 @_ZN10Issue545782f2IcEEcT_(58// CHECK: ret i8 459}60 61namespace Issue55871 {62struct Item {63  consteval Item(char c) :_char{c}{}64  char _char;65};66 67int function(const Item& item1, const Item& item2) {68  return 0;69}70 71int foo() {72  return function(Item{'a'}, Item{'a'});73}74} // namespace Issue5887175 76namespace Issue55065 {77struct Base {78  consteval virtual int Get() const = 0;79};80 81struct Derived : Base {82  consteval int Get() const override {83    return 42;84  }85};86 87int foo() {88  constexpr Derived a;89 90  auto val = a.Get();91  return val;92}93} // namespace Issue5506594 95namespace GH60166 {96 97struct Base {98   void* one = nullptr;99   void* two = nullptr;100};101 102struct Derived : Base {103   void* three = nullptr;104   consteval Derived() = default;105};106 107void method() {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 0110  // CHECK: store ptr null, ptr %0, align 8111  // CHECK: %1 = getelementptr inbounds nuw { ptr, ptr, ptr }, ptr %agg.tmp.ensured, i32 0, i32 1112  // CHECK: store ptr null, ptr %1, align 8113  // CHECK: %2 = getelementptr inbounds nuw { ptr, ptr, ptr }, ptr %agg.tmp.ensured, i32 0, i32 2114  // CHECK: store ptr null, ptr %2, align 8115   (void)Derived();116}117 118} // namespace GH60166119 120namespace GH61142 {121 122template <typename T>123struct Test {124  constexpr static void bar() {125    foo();126  }127  consteval static void foo() {};128};129 130consteval void a() {131  Test<int>::bar();132}133 134void b() {135  Test<int>::bar();136}137 138// Make sure consteval function is not emitted.139// CHECK-NOT: call {{.*}}foo{{.*}}()140// CHECK-NOT: define {{.*}}foo{{.*}}()141 142} // namespace GH61142143