summaryrefslogtreecommitdiff
path: root/clang/test/CodeGenCXX/init-invariant.cpp
diff options
context:
space:
mode:
authorZancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au>2012-09-24 09:58:17 +1000
committerZancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au>2012-09-24 09:58:17 +1000
commit222e2a7620e6520ffaf4fc4e69d79c18da31542e (patch)
tree7bfbc05bfa3b41c8f9d2e56d53a0bc3e310df239 /clang/test/CodeGenCXX/init-invariant.cpp
parent3d206f03985b50beacae843d880bccdc91a9f424 (diff)
Add the clang library to the repo (with some of my changes, too).
Diffstat (limited to 'clang/test/CodeGenCXX/init-invariant.cpp')
-rw-r--r--clang/test/CodeGenCXX/init-invariant.cpp60
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 0000000..9eb1989
--- /dev/null
+++ b/clang/test/CodeGenCXX/init-invariant.cpp
@@ -0,0 +1,60 @@
+// RUN: %clang_cc1 -triple i686-linux-gnu -emit-llvm %s -O0 -o - | FileCheck %s --check-prefix=CHECK-O0
+// RUN: %clang_cc1 -triple i686-linux-gnu -emit-llvm %s -O1 -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.
+
+// Do not produce markers at -O0.
+// CHECK-O0-NOT: llvm.invariant.start
+
+struct A {
+ A();
+ int n;
+};
+
+// CHECK: @a = global {{.*}} zeroinitializer
+extern const A a = A();
+
+struct B {
+ B();
+ mutable int n;
+};
+
+// CHECK: @b = global {{.*}} zeroinitializer
+extern const B b = B();
+
+struct C {
+ C();
+ ~C();
+ int n;
+};
+
+// CHECK: @c = global {{.*}} zeroinitializer
+extern const C c = C();
+
+int f();
+// CHECK: @d = global i32 0
+extern const int d = f();
+
+void e() {
+ static const A a = A();
+}
+
+// CHECK: call void @_ZN1AC1Ev({{.*}}* @a)
+// CHECK: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @a to i8*))
+
+// CHECK: call void @_ZN1BC1Ev({{.*}}* @b)
+// CHECK-NOT: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @b to i8*))
+
+// CHECK: call void @_ZN1CC1Ev({{.*}}* @c)
+// CHECK-NOT: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @c to i8*))
+
+// CHECK: call i32 @_Z1fv(
+// CHECK: store {{.*}}, i32* @d
+// CHECK: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @d to i8*))
+
+// CHECK: define void @_Z1ev(
+// CHECK: call void @_ZN1AC1Ev(%struct.A* @_ZZ1evE1a)
+// CHECK: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @_ZZ1evE1a to i8*))
+// CHECK-NOT: llvm.invariant.end