r212125 - MS ABI: Reference MSVC RTTI from the VFTable
David Majnemer
david.majnemer at gmail.com
Tue Jul 1 15:35:18 PDT 2014
On Tue, Jul 1, 2014 at 2:20 PM, Reid Kleckner <rnk at google.com> wrote:
> On Tue, Jul 1, 2014 at 1:30 PM, David Majnemer <david.majnemer at gmail.com>
> wrote:
>>
>> Modified: cfe/trunk/lib/CodeGen/CGVTables.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVTables.cpp?rev=212125&r1=212124&r2=212125&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/lib/CodeGen/CGVTables.cpp (original)
>> +++ cfe/trunk/lib/CodeGen/CGVTables.cpp Tue Jul 1 15:30:31 2014
>> @@ -431,12 +431,10 @@ void CodeGenVTables::EmitThunks(GlobalDe
>> emitThunk(GD, (*ThunkInfoVector)[I], /*ForVTable=*/false);
>> }
>>
>> -llvm::Constant *
>> -CodeGenVTables::CreateVTableInitializer(const CXXRecordDecl *RD,
>> - const VTableComponent
>> *Components,
>> - unsigned NumComponents,
>> - const VTableLayout::VTableThunkTy
>> *VTableThunks,
>> - unsigned NumVTableThunks) {
>> +llvm::Constant *CodeGenVTables::CreateVTableInitializer(
>> + const CXXRecordDecl *RD, const VTableComponent *Components,
>> + unsigned NumComponents, const VTableLayout::VTableThunkTy
>> *VTableThunks,
>> + unsigned NumVTableThunks, llvm::Constant *RTTI) {
>> SmallVector<llvm::Constant *, 64> Inits;
>>
>> llvm::Type *Int8PtrTy = CGM.Int8PtrTy;
>> @@ -444,9 +442,6 @@ CodeGenVTables::CreateVTableInitializer(
>> llvm::Type *PtrDiffTy =
>> CGM.getTypes().ConvertType(CGM.getContext().getPointerDiffType());
>>
>> - QualType ClassType = CGM.getContext().getTagDeclType(RD);
>> - llvm::Constant *RTTI = CGM.GetAddrOfRTTIDescriptor(ClassType);
>> -
>> unsigned NextVTableThunkIndex = 0;
>>
>> llvm::Constant *PureVirtualFn = nullptr, *DeletedVirtualFn = nullptr;
>> @@ -594,13 +589,14 @@ CodeGenVTables::GenerateConstructionVTab
>> // V-tables are always unnamed_addr.
>> VTable->setUnnamedAddr(true);
>>
>> + llvm::Constant *RTTI = CGM.GetAddrOfRTTIDescriptor(
>> + CGM.getContext().getTagDeclType(Base.getBase()));
>> +
>> // Create and set the initializer.
>> - llvm::Constant *Init =
>> - CreateVTableInitializer(Base.getBase(),
>> - VTLayout->vtable_component_begin(),
>> - VTLayout->getNumVTableComponents(),
>> - VTLayout->vtable_thunk_begin(),
>> - VTLayout->getNumVTableThunks());
>> + llvm::Constant *Init = CreateVTableInitializer(
>> + Base.getBase(), VTLayout->vtable_component_begin(),
>> + VTLayout->getNumVTableComponents(), VTLayout->vtable_thunk_begin(),
>> + VTLayout->getNumVTableThunks(), RTTI);
>> VTable->setInitializer(Init);
>>
>> return VTable;
>>
>
> Why hoist this out to callers?
>
Because there is substantial difference between RTTI in vtables for MSVC
and GCC. MSVC complete object locators need to know which vftable they are
pairing with.
>
>
>> Modified: cfe/trunk/test/CodeGenCXX/dllexport.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllexport.cpp?rev=212125&r1=212124&r2=212125&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/test/CodeGenCXX/dllexport.cpp (original)
>> +++ cfe/trunk/test/CodeGenCXX/dllexport.cpp Tue Jul 1 15:30:31 2014
>> @@ -24,6 +24,9 @@ struct External { int v; };
>> #define INSTVAR(var) template int var;
>> #define INST(func) template void func();
>>
>> +// The vftable for struct W is comdat largest because we have RTTI.
>> +// M32-DAG: $"\01??_7W@@6B@" = comdat largest
>> +
>>
>>
>> //===----------------------------------------------------------------------===//
>> // Globals
>> @@ -518,7 +521,8 @@ struct __declspec(dllexport) W { virtual
>> // Copy ctor:
>> // M32-DAG: define weak_odr dllexport x86_thiscallcc %struct.W*
>> @"\01??0W@@QAE at ABU0@@Z"
>> // vftable:
>> -// M32-DAG: @"\01??_7W@@6B@" = weak_odr dllexport unnamed_addr constant
>> [1 x i8*] [i8* bitcast (void (%struct.W*)* @"\01?foo at W@@UAEXXZ" to i8*)]
>> +// M32-DAG: [[W_VTABLE:@.*]] = private unnamed_addr constant [2 x i8*]
>> [i8* bitcast (%MSRTTICompleteObjectLocator* @"\01??_R4W@@6B@" to i8*),
>> i8* bitcast (void (%struct.W*)* @"\01?foo at W@@UAEXXZ" to i8*)], comdat
>> $"\01??_7W@@6B@"
>> +// M32-DAG: @"\01??_7W@@6B@" = dllexport unnamed_addr alias
>> getelementptr inbounds ([2 x i8*]* [[W_VTABLE]], i32 0, i32 1), comdat
>> $"\01??_7W@@6B@"
>> // G32-DAG: @_ZTV1W = weak_odr dllexport unnamed_addr constant [3 x i8*]
>> [i8* null, i8* bitcast ({ i8*, i8* }* @_ZTI1W to i8*), i8* bitcast (void
>> (%struct.W*)* @_ZN1W3fooEv to i8*)]
>>
>> struct __declspec(dllexport) X : public virtual W {};
>>
>
> This seems like not enough tests, did you forget to add a file?
>
Yep, good catch! r212139.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140701/e00e7ea5/attachment.html>
More information about the cfe-commits
mailing list