80 lines · cpp
1// RUN: %clang_cc1 -triple i686-linux-gnu -std=c++20 -emit-llvm %s -disable-llvm-passes -o - | FileCheck %s --check-prefix=CHECK-O02// RUN: %clang_cc1 -triple i686-linux-gnu -std=c++20 -emit-llvm %s -O1 -disable-llvm-passes -o - | FileCheck %s3 4// Check that we add an llvm.invariant.start.p0i8 to mark when a global becomes5// read-only. If globalopt can fold the initializer, it will then mark the6// variable as constant.7 8// Do not produce markers at -O0.9// CHECK-O0-NOT: llvm.invariant.start.p0i810 11struct A {12 A();13 int n;14};15 16// CHECK: @a ={{.*}} global {{.*}} zeroinitializer17extern const A a = A();18 19struct A2 {20 A2();21 constexpr ~A2() {}22 int n;23};24 25// CHECK: @a2 ={{.*}} global {{.*}} zeroinitializer26extern const A2 a2 = A2();27 28 29struct B {30 B();31 mutable int n;32};33 34// CHECK: @b ={{.*}} global {{.*}} zeroinitializer35extern const B b = B();36 37struct C {38 C();39 ~C();40 int n;41};42 43// CHECK: @c ={{.*}} global {{.*}} zeroinitializer44extern const C c = C();45 46int f();47// CHECK: @d ={{.*}} global i32 048extern const int d = f();49// CHECK: @d2 ={{.*}} addrspace(10) global i32 050extern const int __attribute__((address_space(10))) d2 = f();51 52void e() {53 static const A a = A();54}55 56// CHECK: call void @_ZN1AC1Ev(ptr noundef {{[^,]*}} @a)57// CHECK: call {{.*}}@llvm.invariant.start.p0(i64 4, ptr @a)58 59// CHECK: call void @_ZN2A2C1Ev(ptr noundef {{[^,]*}} @a2)60// CHECK: call {{.*}}@llvm.invariant.start.p0(i64 4, ptr @a2)61 62// CHECK: call void @_ZN1BC1Ev(ptr noundef {{[^,]*}} @b)63// CHECK-NOT: call {{.*}}@llvm.invariant.start.p0(i64 noundef 4, ptr @b)64 65// CHECK: call void @_ZN1CC1Ev(ptr noundef {{[^,]*}} @c)66// CHECK-NOT: call {{.*}}@llvm.invariant.start.p0(i64 noundef 4, ptr @c)67 68// CHECK: call noundef i32 @_Z1fv(69// CHECK: store {{.*}}, ptr @d70// CHECK: call {{.*}}@llvm.invariant.start.p0(i64 4, ptr @d)71 72// CHECK: call noundef i32 @_Z1fv(73// CHECK: store {{.*}}, ptr addrspace(10) @d274// CHECK: call {{.*}}@llvm.invariant.start.p10(i64 4, ptr addrspace(10) @d2)75 76// CHECK-LABEL: define{{.*}} void @_Z1ev(77// CHECK: call void @_ZN1AC1Ev(ptr noundef {{[^,]*}} @_ZZ1evE1a)78// CHECK: call {{.*}}@llvm.invariant.start.p0(i64 4, ptr {{.*}}@_ZZ1evE1a)79// CHECK-NOT: llvm.invariant.end80