<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Apr 16, 2015 at 5:28 PM, Arthur O'Dwyer <span dir="ltr"><<a href="mailto:arthur.j.odwyer+phab+github@gmail.com" target="_blank">arthur.j.odwyer+phab+github@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">================<br>
Comment at: test/CodeGen/no-sanitize-vtpr.cpp:1<br>
@@ +1,2 @@<br>
+// Verify ubsan doesn't emit checks for functions with the no_sanitize_vptr attribute.<br>
+// RUN: %clang_cc1 -fsanitize=vptr -emit-llvm %s -o - | FileCheck %s<br>
----------------<br>
Typo in the name of this test: `vtpr` should be `vptr`.<br>
<br>
================<br>
Comment at: test/CodeGen/no-sanitize-vtpr.cpp:17<br>
@@ +16,3 @@<br>
+  // CHECK-NOT: call void @__ubsan_handle_dynamic_type_cache_miss<br>
+  Foo* foo = static_cast<Foo*>(&bar); // down-casting<br>
+  // CHECK: ret void<br>
----------------<br>
If I understand the feature correctly, the idea is that UBSan inserts runtime checks for various undefined behaviors, including the undefined behavior of down-casting `Bar*` to `Foo*` in the case that the original `Bar*` doesn't actually point to an instance of `Foo`.<br>
<br>
However, this particular test case is statically detectable as undefined behavior, isn't it?</blockquote><div><br></div><div>There could have been a placement new between the creation of bar and the static_cast, changing its dynamic type from Bar to Foo, which (depending on how liberally you want to interpret the standard) might give this function call defined behavior -- in any case, the problem is not the vptr in that case, so the vptr sanitizer should not complain. Alternatively the lifetime of 'bar' might have ended, or (if Bar had a non-trivial default constructor) the lifetime might not have started yet. In those cases, the vptr sanitizer should complain. So I think we're right to insert a dynamic check here.</div><div><br></div><div>When sanitizing for undefined behavior, you can't assume that undefined behavior hasn't happened in order to optimize out checks.</div></div></div></div>