[PATCH] [UBsan] Skip -fsanitize=vptr instrumentations when the pointer value is null
Byoungyoung Lee
byoungyoung at chromium.org
Wed Jul 16 09:26:46 PDT 2014
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()));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4412.11516.patch
Type: text/x-patch
Size: 1245 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140716/8a8578d0/attachment.bin>
More information about the cfe-commits
mailing list