<div dir="auto"><div><div class="gmail_extra"><div class="gmail_quote">On 17 Oct 2016 12:06 pm, "Vedant Kumar via cfe-commits" <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">vsk added a comment.<br>
<br>
Thanks for your feedback so far, and sorry for the delayed response.<br>
<div class="quoted-text"><br>
In <a href="https://reviews.llvm.org/D25448#570014" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D25448#570014</a>, @rjmccall wrote:<br>
<br>
> Wait, can you talk me through the bug here?<br>
<br>
<br>
</div>Derived inherits from Base1 and Base2. We upcast an instance of Derived to Base2, then call a method (f1). Clang figures out that the method has to be Derived::f1. Next, clang passes in a pointer to the vtable pointer for **Base1**, along with the typeinfo for **Base2**, into the sanitizer runtime. This confuses the runtime, which reports that the dynamic type of the object is "Base1", and that this does not match the expected type ("Base2").<br>
<br>
With the 'final' keyword:<br>
<br>
  %6 = ptrtoint <2 x i32 (...)**>* %1 to i64<br>
  call void @__ubsan_handle_dynamic_type_<wbr>cache_miss(@1 (TypeInfo for Base2), i64 %6, ...)<br>
<br>
Without the 'final' keyword:<br>
<br>
  %6 = bitcast <2 x i32 (...)**>* %1 to %class.Derived*<br>
  %7 = getelementptr inbounds %class.Derived, %class.Derived* %6, i64 0, i32 1<br>
  %8 = ptrtoint %class.Base2* %7 to i64, !nosanitize !5<br>
  call void @__ubsan_handle_dynamic_type_<wbr>cache_miss(@1 (TypeInfo for Base2), i64 %8, ...)<br>
<div class="quoted-text"><br>
<br>
<br>
>   Why is final-based devirtualization here different from, say, user-directed devirtualization via a qualified method name?<br>
<br>
</div>I'm not sure. I tested this by removing the 'final' specifier from 'Derived' and calling:<br>
<br>
  obj.Derived::f1()<br>
<br>
In this case, clang passes the correct typeinfo (for Derived) in to the runtime.<br>
<div class="quoted-text"><br>
> It sounds to me from your description that you're not sure why this is happening.  If this indeed only triggers in the presence of multiple inheritance, it might just be the case that you're doing your object-extents analysis starting from the wrong offset.<br>
<br>
</div>It looks like I just haven't done a good job of explaining the issue. The bug really does seem to be that clang isn't passing the right information to the ubsan runtime. However, I'm not sure what the right fix is. Do we disable sanitization in cases where we expect FP's, do we try harder to pass in the right vptr (in this case, the vptr for Base2) into the runtime, or do we try harder to pass in the right typeinfo (in this case, the typeinfo for Derived)?</blockquote></div></div></div><div><br></div><div>The baseline correct behaviour is that we should be passing a pointer to the Base2 subobject, since we're calling a function declared in Base2. However, since we know we can devirtualize, we can do better by passing a pointer to the Derived object and the Derived typeinfo.</div><div><br></div><div>But we should not be working around our broken instrumentation by just turning it off.</div><div><br></div><div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="elided-text">
<a href="https://reviews.llvm.org/D25448" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D25448</a><br>
<br>
<br>
<br>
______________________________<wbr>_________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
</div></blockquote></div><br></div></div></div>