1 // RUN: %clang_cc1 -triple i686-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-O0 2 // RUN: %clang_cc1 -triple i686-linux-gnu -emit-llvm %s -O1 -o - | FileCheck %s 3 4 // Check that we add an llvm.invariant.start 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 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 B { 20 B(); 21 mutable int n; 22 }; 23 24 // CHECK: @b = global {{.*}} zeroinitializer 25 extern const B b = B(); 26 27 struct C { 28 C(); 29 ~C(); 30 int n; 31 }; 32 33 // CHECK: @c = global {{.*}} zeroinitializer 34 extern const C c = C(); 35 36 int f(); 37 // CHECK: @d = global i32 0 38 extern const int d = f(); 39 40 void e() { 41 static const A a = A(); 42 } 43 44 // CHECK: call void @_ZN1AC1Ev({{.*}}* @a) 45 // CHECK: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @a to i8*)) 46 47 // CHECK: call void @_ZN1BC1Ev({{.*}}* @b) 48 // CHECK-NOT: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @b to i8*)) 49 50 // CHECK: call void @_ZN1CC1Ev({{.*}}* @c) 51 // CHECK-NOT: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @c to i8*)) 52 53 // CHECK: call i32 @_Z1fv( 54 // CHECK: store {{.*}}, i32* @d 55 // CHECK: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @d to i8*)) 56 57 // CHECK-LABEL: define void @_Z1ev( 58 // CHECK: call void @_ZN1AC1Ev(%struct.A* @_ZZ1evE1a) 59 // CHECK: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @_ZZ1evE1a to i8*)) 60 // CHECK-NOT: llvm.invariant.end 61