<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Jul 16, 2014 at 9:26 AM, Byoungyoung Lee <span dir="ltr"><<a href="mailto:byoungyoung@chromium.org" target="_blank">byoungyoung@chromium.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">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++.</blockquote>
<div><br></div><div>The other tests for -fsanitize=vptr are in test/CodeGenCXX/catch-undef-behavior.cpp</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="">
<a href="http://reviews.llvm.org/D4412" target="_blank">http://reviews.llvm.org/D4412</a><br>
<br>
Files:<br>
  lib/CodeGen/CGExpr.cpp<br>
  test/CodeGen/ubsan-vptr-null.cpp<br>
<br>
</div><div class="">Index: test/CodeGen/ubsan-vptr-null.cpp<br>
===================================================================<br>
--- test/CodeGen/ubsan-vptr-null.cpp<br>
+++ test/CodeGen/ubsan-vptr-null.cpp<br>
</div>@@ -0,0 +1,18 @@<br>
<div class="">+// Verify ubsan vptr skip null pointer value cases.<br>
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=vptr -emit-llvm %s -o - | FileCheck %s<br>
</div><div class="">+<br>
+class Bar {<br>
+public:<br>
+  virtual ~Bar() {}<br>
+};<br>
+class Foo : public Bar {};<br>
+<br>
+// CHECK-LABEL: @_Z7checkmev<br>
+void checkme() {<br>
</div><div class="">+  // CHECK: [[CMP_RES:%.*]] = icmp ne %class.Foo* %{{[0-9]+}}, null<br>
</div>+  // CHECK: br {{.*}} [[CMP_RES]], label %[[NOT_NULLBB:.*]], label %[[NULLBB:.*]]<br>
+  // CHECK: br label %[[NULLBB]]<br>
<div class="">+  Bar *bar = 0;<br>
+  Foo* foo = static_cast<Foo*>(bar); // static_cast on the null pointer value.<br>
+  return;<br>
+}<br>
</div><div class="">Index: lib/CodeGen/CGExpr.cpp<br>
===================================================================<br>
--- lib/CodeGen/CGExpr.cpp<br>
+++ lib/CodeGen/CGExpr.cpp<br>
</div>@@ -461,7 +461,7 @@<br>
   llvm::Value *Cond = nullptr;<br>
   llvm::BasicBlock *Done = nullptr;<br>
<br>
-  if (SanOpts->Null) {<br>
+  if (SanOpts->Null || TCK == TCK_DowncastPointer) {<br>
<div class="">     // The glvalue must not be an empty glvalue.<br>
</div>     Cond = Builder.CreateICmpNE(<br>
<div class=""><div class="h5">         Address, llvm::Constant::getNullValue(Address->getType()));<br>
</div></div></blockquote></div><br></div></div>