1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple i686-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-O0 2*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple i686-linux-gnu -emit-llvm %s -O1 -o - | FileCheck %s 3*f4a2713aSLionel Sambuc 4*f4a2713aSLionel Sambuc // Check that we add an llvm.invariant.start to mark when a global becomes 5*f4a2713aSLionel Sambuc // read-only. If globalopt can fold the initializer, it will then mark the 6*f4a2713aSLionel Sambuc // variable as constant. 7*f4a2713aSLionel Sambuc 8*f4a2713aSLionel Sambuc // Do not produce markers at -O0. 9*f4a2713aSLionel Sambuc // CHECK-O0-NOT: llvm.invariant.start 10*f4a2713aSLionel Sambuc 11*f4a2713aSLionel Sambuc struct A { 12*f4a2713aSLionel Sambuc A(); 13*f4a2713aSLionel Sambuc int n; 14*f4a2713aSLionel Sambuc }; 15*f4a2713aSLionel Sambuc 16*f4a2713aSLionel Sambuc // CHECK: @a = global {{.*}} zeroinitializer 17*f4a2713aSLionel Sambuc extern const A a = A(); 18*f4a2713aSLionel Sambuc 19*f4a2713aSLionel Sambuc struct B { 20*f4a2713aSLionel Sambuc B(); 21*f4a2713aSLionel Sambuc mutable int n; 22*f4a2713aSLionel Sambuc }; 23*f4a2713aSLionel Sambuc 24*f4a2713aSLionel Sambuc // CHECK: @b = global {{.*}} zeroinitializer 25*f4a2713aSLionel Sambuc extern const B b = B(); 26*f4a2713aSLionel Sambuc 27*f4a2713aSLionel Sambuc struct C { 28*f4a2713aSLionel Sambuc C(); 29*f4a2713aSLionel Sambuc ~C(); 30*f4a2713aSLionel Sambuc int n; 31*f4a2713aSLionel Sambuc }; 32*f4a2713aSLionel Sambuc 33*f4a2713aSLionel Sambuc // CHECK: @c = global {{.*}} zeroinitializer 34*f4a2713aSLionel Sambuc extern const C c = C(); 35*f4a2713aSLionel Sambuc 36*f4a2713aSLionel Sambuc int f(); 37*f4a2713aSLionel Sambuc // CHECK: @d = global i32 0 38*f4a2713aSLionel Sambuc extern const int d = f(); 39*f4a2713aSLionel Sambuc e()40*f4a2713aSLionel Sambucvoid e() { 41*f4a2713aSLionel Sambuc static const A a = A(); 42*f4a2713aSLionel Sambuc } 43*f4a2713aSLionel Sambuc 44*f4a2713aSLionel Sambuc // CHECK: call void @_ZN1AC1Ev({{.*}}* @a) 45*f4a2713aSLionel Sambuc // CHECK: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @a to i8*)) 46*f4a2713aSLionel Sambuc 47*f4a2713aSLionel Sambuc // CHECK: call void @_ZN1BC1Ev({{.*}}* @b) 48*f4a2713aSLionel Sambuc // CHECK-NOT: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @b to i8*)) 49*f4a2713aSLionel Sambuc 50*f4a2713aSLionel Sambuc // CHECK: call void @_ZN1CC1Ev({{.*}}* @c) 51*f4a2713aSLionel Sambuc // CHECK-NOT: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @c to i8*)) 52*f4a2713aSLionel Sambuc 53*f4a2713aSLionel Sambuc // CHECK: call i32 @_Z1fv( 54*f4a2713aSLionel Sambuc // CHECK: store {{.*}}, i32* @d 55*f4a2713aSLionel Sambuc // CHECK: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @d to i8*)) 56*f4a2713aSLionel Sambuc 57*f4a2713aSLionel Sambuc // CHECK-LABEL: define void @_Z1ev( 58*f4a2713aSLionel Sambuc // CHECK: call void @_ZN1AC1Ev(%struct.A* @_ZZ1evE1a) 59*f4a2713aSLionel Sambuc // CHECK: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @_ZZ1evE1a to i8*)) 60*f4a2713aSLionel Sambuc // CHECK-NOT: llvm.invariant.end 61