Richard Smith | 00a8c3f | 2012-02-17 20:12:52 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple i686-linux-gnu -emit-llvm %s -O0 -o - | FileCheck %s --check-prefix=CHECK-O0 |
| 2 | // RUN: %clang_cc1 -triple i686-linux-gnu -emit-llvm %s -O1 -o - | FileCheck %s |
Richard Smith | abb9432 | 2012-02-17 07:31:37 +0000 | [diff] [blame] | 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 | |
Richard Smith | 00a8c3f | 2012-02-17 20:12:52 +0000 | [diff] [blame] | 8 | // Do not produce markers at -O0. |
| 9 | // CHECK-O0-NOT: llvm.invariant.start |
| 10 | |
Richard Smith | abb9432 | 2012-02-17 07:31:37 +0000 | [diff] [blame] | 11 | struct A { |
Richard Smith | 00a8c3f | 2012-02-17 20:12:52 +0000 | [diff] [blame] | 12 | A(); |
Richard Smith | abb9432 | 2012-02-17 07:31:37 +0000 | [diff] [blame] | 13 | int n; |
| 14 | }; |
| 15 | |
| 16 | // CHECK: @a = global {{.*}} zeroinitializer |
| 17 | extern const A a = A(); |
| 18 | |
| 19 | struct B { |
Richard Smith | 00a8c3f | 2012-02-17 20:12:52 +0000 | [diff] [blame] | 20 | B(); |
Richard Smith | abb9432 | 2012-02-17 07:31:37 +0000 | [diff] [blame] | 21 | mutable int n; |
| 22 | }; |
| 23 | |
| 24 | // CHECK: @b = global {{.*}} zeroinitializer |
| 25 | extern const B b = B(); |
| 26 | |
| 27 | struct C { |
Richard Smith | 00a8c3f | 2012-02-17 20:12:52 +0000 | [diff] [blame] | 28 | C(); |
Richard Smith | abb9432 | 2012-02-17 07:31:37 +0000 | [diff] [blame] | 29 | ~C(); |
| 30 | int n; |
| 31 | }; |
| 32 | |
| 33 | // CHECK: @c = global {{.*}} zeroinitializer |
| 34 | extern const C c = C(); |
| 35 | |
Richard Smith | 00a8c3f | 2012-02-17 20:12:52 +0000 | [diff] [blame] | 36 | int f(); |
Richard Smith | abb9432 | 2012-02-17 07:31:37 +0000 | [diff] [blame] | 37 | // CHECK: @d = global i32 0 |
| 38 | extern const int d = f(); |
| 39 | |
| 40 | void e() { |
| 41 | static const A a = A(); |
| 42 | } |
| 43 | |
Richard Smith | abb9432 | 2012-02-17 07:31:37 +0000 | [diff] [blame] | 44 | // CHECK: call void @_ZN1AC1Ev({{.*}}* @a) |
Richard Smith | 00a8c3f | 2012-02-17 20:12:52 +0000 | [diff] [blame] | 45 | // CHECK: call {{.*}}@llvm.invariant.start(i64 -1, i8* bitcast ({{.*}} @a to i8*)) |
Richard Smith | abb9432 | 2012-02-17 07:31:37 +0000 | [diff] [blame] | 46 | |
Richard Smith | abb9432 | 2012-02-17 07:31:37 +0000 | [diff] [blame] | 47 | // CHECK: call void @_ZN1BC1Ev({{.*}}* @b) |
| 48 | // CHECK-NOT: call {{.*}}@llvm.invariant.start(i64 -1, i8* bitcast ({{.*}} @b to i8*)) |
| 49 | |
Richard Smith | abb9432 | 2012-02-17 07:31:37 +0000 | [diff] [blame] | 50 | // CHECK: call void @_ZN1CC1Ev({{.*}}* @c) |
| 51 | // CHECK-NOT: call {{.*}}@llvm.invariant.start(i64 -1, i8* bitcast ({{.*}} @c to i8*)) |
| 52 | |
Richard Smith | abb9432 | 2012-02-17 07:31:37 +0000 | [diff] [blame] | 53 | // CHECK: call i32 @_Z1fv( |
| 54 | // CHECK: store {{.*}}, i32* @d |
| 55 | // CHECK: call {{.*}}@llvm.invariant.start(i64 -1, i8* bitcast ({{.*}} @d to i8*)) |
| 56 | |
| 57 | // CHECK: define void @_Z1ev( |
| 58 | // CHECK: call void @_ZN1AC1Ev(%struct.A* @_ZZ1evE1a) |
| 59 | // CHECK: call {{.*}}@llvm.invariant.start(i64 -1, i8* bitcast ({{.*}} @_ZZ1evE1a to i8*)) |
| 60 | // CHECK-NOT: llvm.invariant.end |