summaryrefslogtreecommitdiffstats
path: root/test/CodeGenCXX/ubsan-type-checks.cpp
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2017-08-02 18:10:31 +0000
committerVedant Kumar <vsk@apple.com>2017-08-02 18:10:31 +0000
commit63a4e484860278f8a187fea35563d9a0ceed2db1 (patch)
tree405da97822ee96acf444033a6b8cd654b8e7978d /test/CodeGenCXX/ubsan-type-checks.cpp
parentd9009e558ab4d45eefae9d11d24951a61c3bb54b (diff)
[ubsan] Have -fsanitize=vptr emit a null check if -fsanitize=null isn't available
In r309007, I made -fsanitize=null a hard prerequisite for -fsanitize=vptr. I did not see the need for the two checks to have separate null checking logic for the same pointer. I expected the two checks to either always be enabled together, or to be mutually compatible. In the mailing list discussion re: r309007 it became clear that that isn't the case. If a codebase is -fsanitize=vptr clean but not -fsanitize=null clean, it's useful to have -fsanitize=vptr emit its own null check. That's what this patch does: with it, -fsanitize=vptr can be used without -fsanitize=null. Differential Revision: https://reviews.llvm.org/D36112 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@309846 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CodeGenCXX/ubsan-type-checks.cpp')
-rw-r--r--test/CodeGenCXX/ubsan-type-checks.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/test/CodeGenCXX/ubsan-type-checks.cpp b/test/CodeGenCXX/ubsan-type-checks.cpp
index cc2d4d6e79..e53ab2466e 100644
--- a/test/CodeGenCXX/ubsan-type-checks.cpp
+++ b/test/CodeGenCXX/ubsan-type-checks.cpp
@@ -44,17 +44,22 @@ struct Dog : Animal {
// VPTR-LABEL: define void @_Z12invalid_castP3Cat
void invalid_cast(Cat *cat = nullptr) {
- // First, null check the pointer:
+ // If -fsanitize=null is available, we'll reuse its check:
//
// VPTR: [[ICMP:%.*]] = icmp ne %struct.Dog* {{.*}}, null
// VPTR-NEXT: br i1 [[ICMP]]
// VPTR: call void @__ubsan_handle_type_mismatch
- //
- // Once we're done emitting the null check, reuse the check to see if we can
- // proceed to the vptr check:
- //
+ // VPTR-NOT: icmp ne %struct.Dog* {{.*}}, null
// VPTR: br i1 [[ICMP]]
// VPTR: call void @__ubsan_handle_dynamic_type_cache_miss
+ //
+ // Fall back to the vptr sanitizer's null check when -fsanitize=null isn't
+ // available.
+ //
+ // VPTR_NO_NULL-NOT: call void @__ubsan_handle_type_mismatch
+ // VPTR_NO_NULL: [[ICMP:%.*]] = icmp ne %struct.Dog* {{.*}}, null
+ // VPTR_NO_NULL-NEXT: br i1 [[ICMP]]
+ // VPTR_NO_NULL: call void @__ubsan_handle_dynamic_type_cache_miss
auto *badDog = reinterpret_cast<Dog *>(cat);
badDog->speak();
}