summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2012-08-24 00:54:33 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2012-08-24 00:54:33 +0000
commit69d0d2626a4f548b5a428f4e0f5c3f1fe65a2548 (patch)
tree99c23222a860523fcf5ca4ac986547cfd99f3782 /clang/test
parent6167ab281965d4ebbcff77c1f392050bcd1c5e79 (diff)
downloadbcm5719-llvm-69d0d2626a4f548b5a428f4e0f5c3f1fe65a2548.tar.gz
bcm5719-llvm-69d0d2626a4f548b5a428f4e0f5c3f1fe65a2548.zip
New -fcatch-undefined-behavior features:
* when checking that a pointer or reference refers to appropriate storage for a type, also check the alignment and perform a null check * check that references are bound to appropriate storage * check that 'this' has appropriate storage in member accesses and member function calls llvm-svn: 162523
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/CodeGen/catch-undef-behavior.c10
-rw-r--r--clang/test/CodeGenCXX/catch-undef-behavior.cpp68
2 files changed, 75 insertions, 3 deletions
diff --git a/clang/test/CodeGen/catch-undef-behavior.c b/clang/test/CodeGen/catch-undef-behavior.c
index ee0b6586dd8..8c45fa50456 100644
--- a/clang/test/CodeGen/catch-undef-behavior.c
+++ b/clang/test/CodeGen/catch-undef-behavior.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fcatch-undefined-behavior -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -fcatch-undefined-behavior -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s
// PR6805
// CHECK: @foo
@@ -11,7 +11,11 @@ void foo() {
// CHECK: @bar
int bar(int *a) {
- // CHECK: objectsize
- // CHECK: icmp uge
+ // CHECK: %[[SIZE:.*]] = call i64 @llvm.objectsize.i64
+ // CHECK-NEXT: icmp uge i64 %[[SIZE]], 4
+
+ // CHECK: %[[PTRINT:.*]] = ptrtoint
+ // CHECK-NEXT: %[[MISALIGN:.*]] = and i64 %[[PTRINT]], 3
+ // CHECK-NEXT: icmp eq i64 %[[MISALIGN]], 0
return *a;
}
diff --git a/clang/test/CodeGenCXX/catch-undef-behavior.cpp b/clang/test/CodeGenCXX/catch-undef-behavior.cpp
new file mode 100644
index 00000000000..ed0a7763f51
--- /dev/null
+++ b/clang/test/CodeGenCXX/catch-undef-behavior.cpp
@@ -0,0 +1,68 @@
+// RUN: %clang_cc1 -fcatch-undefined-behavior -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s
+
+// CHECK: @_Z17reference_binding
+void reference_binding(int *p) {
+ // C++ core issue 453: If an lvalue to which a reference is directly bound
+ // designates neither an existing object or function of an appropriate type,
+ // nor a region of storage of suitable size and alignment to contain an object
+ // of the reference's type, the behavior is undefined.
+
+ // CHECK: icmp ne {{.*}}, null
+
+ // CHECK: %[[SIZE:.*]] = call i64 @llvm.objectsize.i64
+ // CHECK-NEXT: icmp uge i64 %[[SIZE]], 4
+
+ // CHECK: %[[PTRINT:.*]] = ptrtoint
+ // CHECK-NEXT: %[[MISALIGN:.*]] = and i64 %[[PTRINT]], 3
+ // CHECK-NEXT: icmp eq i64 %[[MISALIGN]], 0
+ int &r = *p;
+}
+
+struct S {
+ double d;
+ int a, b;
+ virtual int f();
+};
+
+// CHECK: @_Z13member_access
+void member_access(S *p) {
+ // (1) Check 'p' is appropriately sized and aligned for member access.
+
+ // FIXME: Check vptr is for 'S' or a class derived from 'S'.
+
+ // CHECK: icmp ne {{.*}}, null
+
+ // CHECK: %[[SIZE:.*]] = call i64 @llvm.objectsize.i64
+ // CHECK-NEXT: icmp uge i64 %[[SIZE]], 24
+
+ // CHECK: %[[PTRINT:.*]] = ptrtoint
+ // CHECK-NEXT: %[[MISALIGN:.*]] = and i64 %[[PTRINT]], 7
+ // CHECK-NEXT: icmp eq i64 %[[MISALIGN]], 0
+
+ // (2) Check 'p->b' is appropriately sized and aligned for a load.
+
+ // FIXME: Suppress this in the trivial case of a member access, because we
+ // know we've just checked the member access expression itself.
+
+ // CHECK: %[[SIZE:.*]] = call i64 @llvm.objectsize.i64
+ // CHECK-NEXT: icmp uge i64 %[[SIZE]], 4
+
+ // CHECK: %[[PTRINT:.*]] = ptrtoint
+ // CHECK-NEXT: %[[MISALIGN:.*]] = and i64 %[[PTRINT]], 3
+ // CHECK-NEXT: icmp eq i64 %[[MISALIGN]], 0
+ int k = p->b;
+
+ // (3) Check 'p' is appropriately sized and aligned for member function call.
+
+ // FIXME: Check vptr is for 'S' or a class derived from 'S'.
+
+ // CHECK: icmp ne {{.*}}, null
+
+ // CHECK: %[[SIZE:.*]] = call i64 @llvm.objectsize.i64
+ // CHECK-NEXT: icmp uge i64 %[[SIZE]], 24
+
+ // CHECK: %[[PTRINT:.*]] = ptrtoint
+ // CHECK-NEXT: %[[MISALIGN:.*]] = and i64 %[[PTRINT]], 7
+ // CHECK-NEXT: icmp eq i64 %[[MISALIGN]], 0
+ k = p->f();
+}
OpenPOWER on IntegriCloud