Update the patch as commented except the test cast folding. Richard, could you
please point which file should I fold into for the testcase? As far as I
checked, all existing ubsan tests are written in C (except type-blacklist one),
but this case has to be done in C++.
http://reviews.llvm.org/D4412
Files:
lib/CodeGen/CGExpr.cpp
test/CodeGen/ubsan-vptr-null.cpp
Index: test/CodeGen/ubsan-vptr-null.cpp
===================================================================
--- test/CodeGen/ubsan-vptr-null.cpp
+++ test/CodeGen/ubsan-vptr-null.cpp
@@ -0,0 +1,18 @@
+// Verify ubsan vptr skip null pointer value cases.
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=vptr -emit-llvm %s -o -
| FileCheck %s
+
+class Bar {
+public:
+ virtual ~Bar() {}
+};
+class Foo : public Bar {};
+
+// CHECK-LABEL: @_Z7checkmev
+void checkme() {
+ // CHECK: [[CMP_RES:%.*]] = icmp ne %class.Foo* %{{[0-9]+}}, null
+ // CHECK: br {{.*}} [[CMP_RES]], label %[[NOT_NULLBB:.*]], label
%[[NULLBB:.*]]
+ // CHECK: br label %[[NULLBB]]
+ Bar *bar = 0;
+ Foo* foo = static_cast<Foo*>(bar); // static_cast on the null pointer value.
+ return;
+}
Index: lib/CodeGen/CGExpr.cpp
===================================================================
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -461,7 +461,7 @@
llvm::Value *Cond = nullptr;
llvm::BasicBlock *Done = nullptr;
- if (SanOpts->Null) {
+ if (SanOpts->Null || TCK == TCK_DowncastPointer) {
// The glvalue must not be an empty glvalue.
Cond = Builder.CreateICmpNE(
Address, llvm::Constant::getNullValue(Address->getType()));
Index: test/CodeGen/ubsan-vptr-null.cpp
===================================================================
--- test/CodeGen/ubsan-vptr-null.cpp
+++ test/CodeGen/ubsan-vptr-null.cpp
@@ -0,0 +1,18 @@
+// Verify ubsan vptr skip null pointer value cases.
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=vptr -emit-llvm %s -o - | FileCheck %s
+
+class Bar {
+public:
+ virtual ~Bar() {}
+};
+class Foo : public Bar {};
+
+// CHECK-LABEL: @_Z7checkmev
+void checkme() {
+ // CHECK: [[CMP_RES:%.*]] = icmp ne %class.Foo* %{{[0-9]+}}, null
+ // CHECK: br {{.*}} [[CMP_RES]], label %[[NOT_NULLBB:.*]], label %[[NULLBB:.*]]
+ // CHECK: br label %[[NULLBB]]
+ Bar *bar = 0;
+ Foo* foo = static_cast<Foo*>(bar); // static_cast on the null pointer value.
+ return;
+}
Index: lib/CodeGen/CGExpr.cpp
===================================================================
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -461,7 +461,7 @@
llvm::Value *Cond = nullptr;
llvm::BasicBlock *Done = nullptr;
- if (SanOpts->Null) {
+ if (SanOpts->Null || TCK == TCK_DowncastPointer) {
// The glvalue must not be an empty glvalue.
Cond = Builder.CreateICmpNE(
Address, llvm::Constant::getNullValue(Address->getType()));
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits