diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-02-17 07:31:37 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-02-17 07:31:37 +0000 |
commit | 08a51446213bb26cb0eaaefeb91d4e0c23084759 (patch) | |
tree | 1fd2cb3dc0b5aa58ef12496f7b859233db934de6 /clang/test/CodeGenCXX/init-invariant.cpp | |
parent | 2939e6e136a6a7b26367dd43cd3a858054228a4e (diff) | |
download | bcm5719-llvm-08a51446213bb26cb0eaaefeb91d4e0c23084759.tar.gz bcm5719-llvm-08a51446213bb26cb0eaaefeb91d4e0c23084759.zip |
The clang half of r150794: after the construction of a global or static const
variable ends, if the variable has a trivial destructor and no mutable
subobjects then emit an llvm.invariant.start call for it. globalopt knows to
make the variable const when evaluating this.
llvm-svn: 150798
Diffstat (limited to 'clang/test/CodeGenCXX/init-invariant.cpp')
-rw-r--r-- | clang/test/CodeGenCXX/init-invariant.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/clang/test/CodeGenCXX/init-invariant.cpp b/clang/test/CodeGenCXX/init-invariant.cpp new file mode 100644 index 00000000000..da17303b2d4 --- /dev/null +++ b/clang/test/CodeGenCXX/init-invariant.cpp @@ -0,0 +1,60 @@ +// RUN: %clang_cc1 -triple i686-linux-gnu -emit-llvm %s -o - | FileCheck %s + +// Check that we add an llvm.invariant.start to mark when a global becomes +// read-only. If globalopt can fold the initializer, it will then mark the +// variable as constant. + +struct A { + A() : n(42) {} + int n; +}; + +// CHECK: @a = global {{.*}} zeroinitializer +extern const A a = A(); + +struct B { + B() : n(76) {} + mutable int n; +}; + +// CHECK: @b = global {{.*}} zeroinitializer +extern const B b = B(); + +struct C { + C() : n(81) {} + ~C(); + int n; +}; + +// CHECK: @c = global {{.*}} zeroinitializer +extern const C c = C(); + +int f() { return 5; } +// CHECK: @d = global i32 0 +extern const int d = f(); + +void e() { + static const A a = A(); +} + +// CHECK: define internal void @__cxx_global_var_init +// CHECK: call void @_ZN1AC1Ev({{.*}}* @a) +// CHECK-NEXT: call {{.*}}@llvm.invariant.start(i64 -1, i8* bitcast ({{.*}} @a to i8*)) + +// CHECK: define internal void @__cxx_global_var_init +// CHECK: call void @_ZN1BC1Ev({{.*}}* @b) +// CHECK-NOT: call {{.*}}@llvm.invariant.start(i64 -1, i8* bitcast ({{.*}} @b to i8*)) + +// CHECK: define internal void @__cxx_global_var_init +// CHECK: call void @_ZN1CC1Ev({{.*}}* @c) +// CHECK-NOT: call {{.*}}@llvm.invariant.start(i64 -1, i8* bitcast ({{.*}} @c to i8*)) + +// CHECK: define internal void @__cxx_global_var_init +// CHECK: call i32 @_Z1fv( +// CHECK: store {{.*}}, i32* @d +// CHECK: call {{.*}}@llvm.invariant.start(i64 -1, i8* bitcast ({{.*}} @d to i8*)) + +// CHECK: define void @_Z1ev( +// CHECK: call void @_ZN1AC1Ev(%struct.A* @_ZZ1evE1a) +// CHECK: call {{.*}}@llvm.invariant.start(i64 -1, i8* bitcast ({{.*}} @_ZZ1evE1a to i8*)) +// CHECK-NOT: llvm.invariant.end |