2013-09-04 12:12:25 +08:00
|
|
|
// RUN: %clang_cc1 -triple i686-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-O0
|
2012-02-18 04:12:52 +08:00
|
|
|
// RUN: %clang_cc1 -triple i686-linux-gnu -emit-llvm %s -O1 -o - | FileCheck %s
|
2012-02-17 15:31:37 +08:00
|
|
|
|
2016-07-23 01:50:08 +08:00
|
|
|
// Check that we add an llvm.invariant.start.p0i8 to mark when a global becomes
|
2012-02-17 15:31:37 +08:00
|
|
|
// read-only. If globalopt can fold the initializer, it will then mark the
|
|
|
|
// variable as constant.
|
|
|
|
|
2012-02-18 04:12:52 +08:00
|
|
|
// Do not produce markers at -O0.
|
2016-07-23 01:50:08 +08:00
|
|
|
// CHECK-O0-NOT: llvm.invariant.start.p0i8
|
2012-02-18 04:12:52 +08:00
|
|
|
|
2012-02-17 15:31:37 +08:00
|
|
|
struct A {
|
2012-02-18 04:12:52 +08:00
|
|
|
A();
|
2012-02-17 15:31:37 +08:00
|
|
|
int n;
|
|
|
|
};
|
|
|
|
|
|
|
|
// CHECK: @a = global {{.*}} zeroinitializer
|
|
|
|
extern const A a = A();
|
|
|
|
|
|
|
|
struct B {
|
2012-02-18 04:12:52 +08:00
|
|
|
B();
|
2012-02-17 15:31:37 +08:00
|
|
|
mutable int n;
|
|
|
|
};
|
|
|
|
|
|
|
|
// CHECK: @b = global {{.*}} zeroinitializer
|
|
|
|
extern const B b = B();
|
|
|
|
|
|
|
|
struct C {
|
2012-02-18 04:12:52 +08:00
|
|
|
C();
|
2012-02-17 15:31:37 +08:00
|
|
|
~C();
|
|
|
|
int n;
|
|
|
|
};
|
|
|
|
|
|
|
|
// CHECK: @c = global {{.*}} zeroinitializer
|
|
|
|
extern const C c = C();
|
|
|
|
|
2012-02-18 04:12:52 +08:00
|
|
|
int f();
|
2012-02-17 15:31:37 +08:00
|
|
|
// CHECK: @d = global i32 0
|
|
|
|
extern const int d = f();
|
|
|
|
|
|
|
|
void e() {
|
|
|
|
static const A a = A();
|
|
|
|
}
|
|
|
|
|
2018-10-15 23:43:00 +08:00
|
|
|
// CHECK: call void @_ZN1AC1Ev({{.*}}* nonnull @a)
|
2016-07-23 01:50:08 +08:00
|
|
|
// CHECK: call {{.*}}@llvm.invariant.start.p0i8(i64 4, i8* bitcast ({{.*}} @a to i8*))
|
2012-02-17 15:31:37 +08:00
|
|
|
|
2018-10-15 23:43:00 +08:00
|
|
|
// CHECK: call void @_ZN1BC1Ev({{.*}}* nonnull @b)
|
2016-07-23 01:50:08 +08:00
|
|
|
// CHECK-NOT: call {{.*}}@llvm.invariant.start.p0i8(i64 4, i8* bitcast ({{.*}} @b to i8*))
|
2012-02-17 15:31:37 +08:00
|
|
|
|
2018-10-15 23:43:00 +08:00
|
|
|
// CHECK: call void @_ZN1CC1Ev({{.*}}* nonnull @c)
|
2016-07-23 01:50:08 +08:00
|
|
|
// CHECK-NOT: call {{.*}}@llvm.invariant.start.p0i8(i64 4, i8* bitcast ({{.*}} @c to i8*))
|
2012-02-17 15:31:37 +08:00
|
|
|
|
|
|
|
// CHECK: call i32 @_Z1fv(
|
|
|
|
// CHECK: store {{.*}}, i32* @d
|
2016-07-23 01:50:08 +08:00
|
|
|
// CHECK: call {{.*}}@llvm.invariant.start.p0i8(i64 4, i8* bitcast ({{.*}} @d to i8*))
|
2012-02-17 15:31:37 +08:00
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z1ev(
|
2018-10-15 23:43:00 +08:00
|
|
|
// CHECK: call void @_ZN1AC1Ev(%struct.A* nonnull @_ZZ1evE1a)
|
2016-07-23 01:50:08 +08:00
|
|
|
// CHECK: call {{.*}}@llvm.invariant.start.p0i8(i64 4, i8* {{.*}}bitcast ({{.*}} @_ZZ1evE1a to i8*))
|
2012-02-17 15:31:37 +08:00
|
|
|
// CHECK-NOT: llvm.invariant.end
|