| 1 |
// RUN: %clang_cc1 -triple i686-linux-gnu -std=c++20 -emit-llvm %s -disable-llvm-passes -o - | FileCheck %s --check-prefix=CHECK-O0 |
| 2 |
// RUN: %clang_cc1 -triple i686-linux-gnu -std=c++20 -emit-llvm %s -O1 -disable-llvm-passes -o - | FileCheck %s |
| 3 |
|
| 4 |
// Check that we add an llvm.invariant.start.p0i8 to mark when a global becomes |
| 5 |
// read-only. If globalopt can fold the initializer, it will then mark the |
| 6 |
// variable as constant. |
| 7 |
|
| 8 |
// Do not produce markers at -O0. |
| 9 |
// CHECK-O0-NOT: llvm.invariant.start.p0i8 |
| 10 |
|
| 11 |
struct A { |
| 12 |
A(); |
| 13 |
int n; |
| 14 |
}; |
| 15 |
|
| 16 |
// CHECK: @a ={{.*}} global {{.*}} zeroinitializer |
| 17 |
extern const A a = A(); |
| 18 |
|
| 19 |
struct A2 { |
| 20 |
A2(); |
| 21 |
constexpr ~A2() {} |
| 22 |
int n; |
| 23 |
}; |
| 24 |
|
| 25 |
// CHECK: @a2 ={{.*}} global {{.*}} zeroinitializer |
| 26 |
extern const A2 a2 = A2(); |
| 27 |
|
| 28 |
|
| 29 |
struct B { |
| 30 |
B(); |
| 31 |
mutable int n; |
| 32 |
}; |
| 33 |
|
| 34 |
// CHECK: @b ={{.*}} global {{.*}} zeroinitializer |
| 35 |
extern const B b = B(); |
| 36 |
|
| 37 |
struct C { |
| 38 |
C(); |
| 39 |
~C(); |
| 40 |
int n; |
| 41 |
}; |
| 42 |
|
| 43 |
// CHECK: @c ={{.*}} global {{.*}} zeroinitializer |
| 44 |
extern const C c = C(); |
| 45 |
|
| 46 |
int f(); |
| 47 |
// CHECK: @d ={{.*}} global i32 0 |
| 48 |
extern const int d = f(); |
| 49 |
// CHECK: @d2 ={{.*}} addrspace(10) global i32 0 |
| 50 |
extern const int __attribute__((address_space(10))) d2 = f(); |
| 51 |
|
| 52 |
void 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 @d |
| 70 |
// CHECK: call {{.*}}@llvm.invariant.start.p0(i64 4, ptr @d) |
| 71 |
|
| 72 |
// CHECK: call noundef i32 @_Z1fv( |
| 73 |
// CHECK: store {{.*}}, ptr addrspace(10) @d2 |
| 74 |
// 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.end |