<div dir="ltr">Thanks for tackling and reducing this!  This was reported in July, and it's a shame we didn't report it to them before they went from preview to release: <a href="http://llvm.org/bugs/show_bug.cgi?id=16606">http://llvm.org/bugs/show_bug.cgi?id=16606</a></div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Nov 1, 2013 at 12:16 PM, Aaron Ballman <span dir="ltr"><<a href="mailto:aaron@aaronballman.com" target="_blank">aaron@aaronballman.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I have this as narrowed down as I think I can get it, and I've<br>
reported it to Microsoft Connect.<br>
<br>
<a href="https://connect.microsoft.com/VisualStudio/feedback/details/807479/miscompile-involving-using-declarations-and-multiple-inheritance" target="_blank">https://connect.microsoft.com/VisualStudio/feedback/details/807479/miscompile-involving-using-declarations-and-multiple-inheritance</a><br>

<br>
The miscompile seems to happen as a result of multiple inheritance<br>
(the thunk is missing in 2013 but there in 2012), and seems to have<br>
something to do with the using declaration importing two methods.  At<br>
least, from what I can tell, when I remove the const version of the<br>
method, the thunk comes back in 2013.<br>
<span class="HOEnZb"><font color="#888888"><br>
~Aaron<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On Thu, Oct 31, 2013 at 5:16 PM, Aaron Ballman <<a href="mailto:aaron@aaronballman.com">aaron@aaronballman.com</a>> wrote:<br>
> While updating clang to VS 2013, I've seen numerous miscompiles on x86<br>
> that did not appear in VS 2012 related to the Redeclarable class.  It<br>
> seems that VS 2012 would properly calculate the offset to the base<br>
> class, while VS 2013 would not.  Specifically, VS 2012 would generate<br>
> the following code:<br>
><br>
>   RecordDecl *getPreviousDecl() {<br>
> 025FF040  push        ebp<br>
> 025FF041  mov         ebp,esp<br>
> 025FF043  push        ecx<br>
> 025FF044  mov         dword ptr [this],0CCCCCCCCh<br>
> 025FF04B  mov         dword ptr [this],ecx<br>
>     return cast_or_null<RecordDecl>(TagDecl::getPreviousDecl());<br>
> 025FF04E  mov         ecx,dword ptr [this]<br>
> 025FF051  add         ecx,34h<br>
> 025FF054  call<br>
> clang::Redeclarable<clang::TagDecl>::getPreviousDecl (025FEF40h)<br>
> 025FF059  push        eax<br>
> 025FF05A  call<br>
> llvm::cast_or_null<clang::RecordDecl,clang::TagDecl> (025A9850h)<br>
> 025FF05F  add         esp,4<br>
>   }<br>
><br>
> VS 2013, however, is missing the add ecx, 34h instruction:<br>
><br>
>   RecordDecl *getPreviousDecl() {<br>
> 02500010  push        ebp<br>
> 02500011  mov         ebp,esp<br>
> 02500013  push        ecx<br>
> 02500014  mov         dword ptr [this],0CCCCCCCCh<br>
> 0250001B  mov         dword ptr [this],ecx<br>
>     return cast_or_null<RecordDecl>(TagDecl::getPreviousDecl());<br>
> 0250001E  mov         ecx,dword ptr [this]<br>
> 02500021  call<br>
> clang::Redeclarable<clang::TagDecl>::getPreviousDecl (024FFF10h)<br>
> 02500026  push        eax<br>
> 02500027  call<br>
> llvm::cast_or_null<clang::RecordDecl,clang::TagDecl> (024AA9B0h)<br>
> 0250002C  add         esp,4<br>
><br>
> This would cause crashes in getPreviousDecl.  Unfortunately, this also<br>
> affects other calls on Redeclarable such as getMostRecentDecl.<br>
><br>
> This patch "addresses" the miscompile such that it now compiles<br>
> properly for VS 2013 as well as VS 2012.  Instead of calling through a<br>
> scoped lookup on a method coming from Redeclarable, it statically<br>
> casts the this pointer and calls the method.  This seems to force<br>
> Visual Studio to generate the proper code.<br>
><br>
> ~Aaron<br>
</div></div></blockquote></div><br></div>