[PATCH] [UBsan] Skip -fsanitize=vptr instrumentations when the pointer value is null
Richard Smith
richard at metafoo.co.uk
Wed Jul 16 17:20:44 PDT 2014
On Wed, Jul 16, 2014 at 9:26 AM, Byoungyoung Lee <byoungyoung at chromium.org>
wrote:
> 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++.
The other tests for -fsanitize=vptr are
in test/CodeGenCXX/catch-undef-behavior.cpp
> 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 --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140716/aa6c89a6/attachment.html>
More information about the cfe-commits
mailing list