[PATCH] MS ABI: Give thunks linkonce_odr linkage

Hans Wennborg hans at chromium.org
Mon Jun 2 14:19:40 PDT 2014

On Mon, Jun 2, 2014 at 12:48 PM, Reid Kleckner <rnk at google.com> wrote:
> I think it's handling this corner case:
>   struct Incomplete;
>   struct A { int a; virtual A *bar(); };
>   struct B { int b; virtual B *foo(Incomplete); };
>   struct C : A, B { int c; virtual C *foo(Incomplete); };
>   C c;
> MSVC gives this error:
>   t.cpp(5) : error C2664: 'C *C::foo(Incomplete)' : cannot convert argument 1 from 'Incomplete' to 'Incomplete'
>         Source or target has incomplete type
>         This diagnostic occurred in the compiler generated function 'B *C::foo(Incomplete)'
> Clang on the other hand relies on the TU defining the virtual function to emit code for the thunk.  Therefore I think the correct linkage is weak_odr.  This should also be applicable to the Itanium C++ ABI.

In Itanium, we seem to emit thunks either as strong definitions or
linkonce_odr. If I define C::foo from your example in a separate TU,
it gets a strong definition. If I make that inline, it becomes
linkonce_odr. There's also a test in
test/CodeGenCXX/thunk-linkonce-odr.cpp which says "Thunks should be
marked as "linkonce ODR" not "weak""

Maybe the MS situation is that since we emit thunks in different
places than MSVC, we can't use strong definitions and therefore chose
to just always use weak?

In any case, changing to weak_odr for the MS ABI sounds good; I'll
update the patch.

More information about the cfe-commits mailing list