summaryrefslogtreecommitdiffstats
path: root/clang/test/CodeGenCXX/catch-undef-behavior.cpp
diff options
context:
space:
mode:
authorAlexey Samsonov <vonosmas@gmail.com>2014-10-13 23:59:00 +0000
committerAlexey Samsonov <vonosmas@gmail.com>2014-10-13 23:59:00 +0000
commiteb47d8a2c880611d79a468d04f287e868b8e241a (patch)
treecba22a0d20aed83e80a543af4d842bd5e93cc560 /clang/test/CodeGenCXX/catch-undef-behavior.cpp
parent0809b2ddc3a8661a55f818dbed8ea71a86e3802a (diff)
downloadbcm5719-llvm-eb47d8a2c880611d79a468d04f287e868b8e241a.tar.gz
bcm5719-llvm-eb47d8a2c880611d79a468d04f287e868b8e241a.zip
Sanitize upcasts and conversion to virtual base.
This change adds UBSan check to upcasts. Namely, when we perform derived-to-base conversion, we: 1) check that the pointer-to-derived has suitable alignment and underlying storage, if this pointer is non-null. 2) if vptr-sanitizer is enabled, and we perform conversion to virtual base, we check that pointer-to-derived has a matching vptr. llvm-svn: 219642
Diffstat (limited to 'clang/test/CodeGenCXX/catch-undef-behavior.cpp')
-rw-r--r--clang/test/CodeGenCXX/catch-undef-behavior.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/clang/test/CodeGenCXX/catch-undef-behavior.cpp b/clang/test/CodeGenCXX/catch-undef-behavior.cpp
index 333855d0ba6..5bf31c1ca40 100644
--- a/clang/test/CodeGenCXX/catch-undef-behavior.cpp
+++ b/clang/test/CodeGenCXX/catch-undef-behavior.cpp
@@ -404,6 +404,40 @@ void indirect_function_call(void (*p)(int)) {
p(42);
}
+namespace UpcastPointerTest {
+struct S {};
+struct T : S { double d; };
+struct V : virtual S {};
+
+// CHECK-LABEL: upcast_pointer
+S* upcast_pointer(T* t) {
+ // Check for null pointer
+ // CHECK: %[[NONNULL:.*]] = icmp ne {{.*}}, null
+ // CHECK: br i1 %[[NONNULL]]
+
+ // Check alignment
+ // CHECK: %[[MISALIGN:.*]] = and i64 %{{.*}}, 7
+ // CHECK: icmp eq i64 %[[MISALIGN]], 0
+
+ // CHECK: call void @__ubsan_handle_type_mismatch
+ return t;
+}
+
+V getV();
+
+// CHECK-LABEL: upcast_to_vbase
+void upcast_to_vbase() {
+ // No need to check for null here, as we have a temporary here.
+
+ // CHECK-NOT: br i1
+
+ // CHECK: call i64 @llvm.objectsize
+ // CHECK: call void @__ubsan_handle_type_mismatch
+ // CHECK: call void @__ubsan_handle_dynamic_type_cache_miss
+ const S& s = getV();
+}
+}
+
namespace CopyValueRepresentation {
// CHECK-LABEL: define {{.*}} @_ZN23CopyValueRepresentation2S3aSERKS0_
// CHECK-NOT: call {{.*}} @__ubsan_handle_load_invalid_value
OpenPOWER on IntegriCloud