LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 25641 - clang-cl: vtordisp thunks not emitted for functions with class template specializations in their signatures
Summary: clang-cl: vtordisp thunks not emitted for functions with class template speci...
Status: RESOLVED FIXED
Alias: None
Product: clang
Classification: Unclassified
Component: -New Bugs (show other bugs)
Version: trunk
Hardware: All All
: P normal
Assignee: Unassigned Clang Bugs
URL:
Keywords:
: 33417 36952 (view as bug list)
Depends on:
Blocks:
 
Reported: 2015-11-25 15:02 PST by Stephan Bergmann
Modified: 2018-04-02 15:55 PDT (History)
5 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stephan Bergmann 2015-11-25 15:02:41 PST
On recent trunk:

> $ cat test.cc
> struct Color {};
> template<typename> struct SharedPtr {};
> struct Canvas {
>     virtual ~Canvas() {}
>     virtual void getClip() = 0;
>     virtual SharedPtr<Color> createColor() = 0;
> };
> struct BitmapCanvas: virtual Canvas {};
> struct ImplCanvas: virtual Canvas {
>     virtual ~ImplCanvas();
>     void getClip() override;
>     SharedPtr<Color> createColor() override;
> };
> struct ImplBitmapCanvas: virtual BitmapCanvas, virtual ImplCanvas {
>     virtual ~ImplBitmapCanvas();
> };
> ImplBitmapCanvas::~ImplBitmapCanvas() {}
> ImplBitmapCanvas c;

> $ clang-cl -c test.cc

> $ llvm-nm test.obj | grep -F '?getClip@ImplCanvas@@$'
> 00000000 T ?getClip@ImplCanvas@@$4PPPPPPPM@A@EAAXXZ
> 00000000 T ?getClip@ImplCanvas@@$R4BA@M@PPPPPPPM@BA@EAAXXZ

> $ llvm-nm test.obj | grep -F '?createColor@ImplCanvas@@$'
>          U ?createColor@ImplCanvas@@$4PPPPPPPM@A@EAA?AU?$SharedPtr@UColor@@@@XZ
>          U ?createColor@ImplCanvas@@$R4BA@M@PPPPPPPM@BA@EAA?AU?$SharedPtr@UColor@@@@XZ

The vtordisp thunks for getClip are emitted, while those for createColor are erroneously missing.

The reason is that CodeGenVTabels::maybeEmitThunkForVtable (lib/CodeGen/CGVtables.cpp) returns early if !isFuncTypeConvertible, which hits here as the ClassTemplateSpecializationDecl for SharedPtr<Color> is !isCompleteDefinition, as there's no code in Sema that happens to call Sema::RequireCompleteType -> Sema::InstantiateClassTemplateSpecialization on it.
Comment 1 David Majnemer 2015-11-25 17:15:17 PST
Stephan,

The vtordisp thunk should be emitted with whichever TU contains the definition of ImplCanvas::createColor.

Your TU doesn't provide a definition of ImplCanvas::createColor and thus misses out on the thunk.
Comment 2 David Majnemer 2015-11-25 17:28:40 PST
Ah, but MSVC will not provide the thunk if *they* provide the definition... This is indeed an ABI break on our side.
Comment 3 David Majnemer 2017-06-12 09:50:25 PDT
*** Bug 33417 has been marked as a duplicate of this bug. ***
Comment 4 Reid Kleckner 2018-03-31 11:42:56 PDT
*** Bug 36952 has been marked as a duplicate of this bug. ***
Comment 5 Reid Kleckner 2018-04-02 15:55:52 PDT
Should be fixed by r329009.