Skip to content

Commit 2c388db

Browse files
committed
Tweak implementation to make the functions to appear
1 parent d4be529 commit 2c388db

File tree

5 files changed

+35
-49
lines changed

5 files changed

+35
-49
lines changed

clang/include/clang/AST/VTableBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class VTableComponent {
161161
case CK_CompleteDtorPointer:
162162
return GlobalDecl(DtorDecl, CXXDtorType::Dtor_Complete);
163163
case CK_DeletingDtorPointer:
164-
return GlobalDecl(DtorDecl, CXXDtorType::Dtor_Deleting);
164+
return GlobalDecl(DtorDecl, CXXDtorType::Dtor_VectorDeleting);
165165
case CK_VCallOffset:
166166
case CK_VBaseOffset:
167167
case CK_OffsetToTop:

clang/lib/AST/VTableBuilder.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2654,11 +2654,11 @@ class VFTableBuilder {
26542654
MethodVFTableLocation Loc(MI.VBTableIndex, WhichVFPtr.getVBaseWithVPtr(),
26552655
WhichVFPtr.NonVirtualOffset, MI.VFTableIndex);
26562656
if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(MD)) {
2657-
if (!Context.getTargetInfo().getCXXABI().isMicrosoft()) {
2657+
if (!Context.getTargetInfo().getCXXABI().isMicrosoft()) {
26582658
MethodVFTableLocations[GlobalDecl(DD, Dtor_Deleting)] = Loc;
2659-
} else {
2660-
MethodVFTableLocations[GlobalDecl(DD, Dtor_VectorDeleting)] = Loc;
2661-
}
2659+
} else {
2660+
MethodVFTableLocations[GlobalDecl(DD, Dtor_VectorDeleting)] = Loc;
2661+
}
26622662
} else {
26632663
MethodVFTableLocations[MD] = Loc;
26642664
}
@@ -3879,12 +3879,9 @@ MicrosoftVTableContext::getMethodVFTableLocation(GlobalDecl GD) {
38793879
assert(hasVtableSlot(cast<CXXMethodDecl>(GD.getDecl())) &&
38803880
"Only use this method for virtual methods or dtors");
38813881
if (isa<CXXDestructorDecl>(GD.getDecl())) {
3882-
if (!Context.getTargetInfo().getCXXABI().isMicrosoft()) {
3883-
assert(GD.getDtorType() == Dtor_Deleting);
3884-
} else {
3885-
assert(GD.getDtorType() == Dtor_VectorDeleting);
3886-
}
3887-
}
3882+
assert(GD.getDtorType() == Dtor_Deleting ||
3883+
GD.getDtorType() == Dtor_VectorDeleting);
3884+
}
38883885

38893886
GD = GD.getCanonicalDecl();
38903887

clang/lib/CodeGen/CGCXX.cpp

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -205,55 +205,42 @@ bool CodeGenModule::TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D) {
205205
/// this function should be used only where there is an ABI requirement to emit
206206
/// an alias.
207207
void CodeGenModule::EmitDefinitionAsAlias(GlobalDecl AliasDecl, GlobalDecl TargetDecl) {
208-
// Get the mangled names for the alias and the target.
209-
StringRef AliasName = getMangledName(AliasDecl);
210-
StringRef TargetName = getMangledName(TargetDecl);
211208

212-
// Get the LLVM function for the target.
213-
llvm::Function *TargetFunction = cast<llvm::Function>(GetOrCreateLLVMFunction(
214-
TargetName, /*FnType=*/nullptr, TargetDecl, /*ForVTable=*/false,
215-
/*DontDefer=*/true, /*IsThunk=*/false, /*ExtraAttrs=*/llvm::AttributeList(),
216-
ForDefinition));
209+
// Derive the type for the alias.
210+
llvm::PointerType *AliasValueType =
211+
getTypes().GetFunctionType(AliasDecl)->getPointerTo();
212+
auto *Aliasee = cast<llvm::GlobalValue>(GetAddrOfGlobal(TargetDecl));
217213

218214
// Determine the linkage type for the alias.
219215
llvm::GlobalValue::LinkageTypes Linkage = getFunctionLinkage(AliasDecl);
220216

221-
// Ensure that the target has the correct linkage.
222-
TargetFunction->setLinkage(Linkage);
223-
llvm::Type *ElementType = TargetFunction->getValueType();
224-
llvm::GlobalAlias *GA = llvm::GlobalAlias::create(
225-
ElementType, // Type of the aliased value
226-
0, // Address space, usually 0 for the default address space
227-
Linkage, // Linkage of the alias
228-
AliasName, // Name of the alias
229-
TargetFunction, // The aliased value
230-
&getModule()); // The module in which to create the alias
217+
// Create the alias with no name.
218+
auto *Alias = llvm::GlobalAlias::create(AliasValueType, 0, Linkage, "",
219+
Aliasee, &getModule());
220+
// Destructors are always unnamed_addr.
221+
Alias->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
231222

232223
// Set any additional necessary attributes for the alias.
233-
SetCommonAttributes(AliasDecl, GA);
224+
SetCommonAttributes(AliasDecl, Alias);
234225
}
235226

236227
llvm::Function *CodeGenModule::codegenCXXStructor(GlobalDecl GD) {
237228
// The Microsoft ABI requires that the vector deleting destructor
238229
// be weak aliased to the scalar deleting destructor.
239-
if (getTarget().getCXXABI().isMicrosoft() && GD.getDtorType() == Dtor_VectorDeleting) {
230+
auto Dtor = dyn_cast<CXXDestructorDecl>(GD.getDecl());
231+
if (Dtor && getTarget().getCXXABI().isMicrosoft() &&
232+
GD.getDtorType() == Dtor_VectorDeleting) {
240233
const CXXDestructorDecl *DtorDecl = cast<CXXDestructorDecl>(GD.getDecl());
241234

242-
// Create GlobalDecl objects with the correct type for the vector and scalar deleting destructors.
235+
// Create GlobalDecl objects with the correct type for the vector and scalar
236+
// deleting destructors.
243237
GlobalDecl VectorDtorGD(DtorDecl, Dtor_VectorDeleting);
244238
GlobalDecl ScalarDtorGD(DtorDecl, Dtor_Deleting);
245239

246-
// Emit an alias from the vector deleting destructor to the scalar deleting destructor.
240+
// Emit an alias from the vector deleting destructor to the scalar deleting
241+
// destructor.
247242
EmitDefinitionAsAlias(VectorDtorGD, ScalarDtorGD);
248243

249-
// Return the scalar deleting destructor, which is now aliased by the vector deleting destructor.
250-
// Use the mangled name of the scalar deleting destructor.
251-
StringRef MangledName = getMangledName(ScalarDtorGD);
252-
return cast<llvm::Function>(GetOrCreateLLVMFunction(
253-
MangledName, /*FnType=*/nullptr,
254-
ScalarDtorGD, /*ForVTable=*/false,
255-
/*DontDefer=*/true, /*IsThunk=*/false, /*ExtraAttrs=*/llvm::AttributeList(),
256-
ForDefinition));
257244
}
258245
const CGFunctionInfo &FnInfo = getTypes().arrangeCXXStructorDeclaration(GD);
259246
auto *Fn = cast<llvm::Function>(

clang/lib/CodeGen/CGClass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,8 +1544,8 @@ void CodeGenFunction::EmitDestructorBody(FunctionArgList &Args) {
15441544
// outside of the function-try-block, which means it's always
15451545
// possible to delegate the destructor body to the complete
15461546
// destructor. Do so.
1547-
if (DtorType == Dtor_Deleting) {
1548-
if (CXXStructorImplicitParamValue) {
1547+
if (DtorType == Dtor_Deleting || DtorType == Dtor_VectorDeleting) {
1548+
if (CXXStructorImplicitParamValue && DtorType == Dtor_VectorDeleting) {
15491549
EmitConditionalArrayDtorCall(Dtor, *this, CXXStructorImplicitParamValue,
15501550
false);
15511551
}

clang/lib/CodeGen/MicrosoftCXXABI.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,8 @@ class MicrosoftCXXABI : public CGCXXABI {
7070
switch (GD.getDtorType()) {
7171
case Dtor_Complete:
7272
case Dtor_Deleting:
73-
return true;
7473
case Dtor_VectorDeleting:
75-
return true;
74+
return true;
7675
case Dtor_Base:
7776
return false;
7877

@@ -261,7 +260,7 @@ class MicrosoftCXXABI : public CGCXXABI {
261260

262261
// There's only Dtor_Deleting in vftable but it shares the this
263262
// adjustment with the base one, so look up the deleting one instead.
264-
LookupGD = GlobalDecl(DD, Dtor_Deleting);
263+
LookupGD = GlobalDecl(DD, Dtor_VectorDeleting);
265264
}
266265
MethodVFTableLocation ML =
267266
CGM.getMicrosoftVTableContext().getMethodVFTableLocation(LookupGD);
@@ -895,7 +894,8 @@ void MicrosoftCXXABI::emitVirtualObjectDelete(CodeGenFunction &CGF,
895894
// FIXME: Provide a source location here even though there's no
896895
// CXXMemberCallExpr for dtor call.
897896
bool UseGlobalDelete = DE->isGlobalDelete();
898-
CXXDtorType DtorType = UseGlobalDelete ? Dtor_Complete : Dtor_Deleting;
897+
// FIXME check that vector deletion is actually required.
898+
CXXDtorType DtorType = UseGlobalDelete ? Dtor_Complete : Dtor_VectorDeleting;
899899
llvm::Value *MDThis = EmitVirtualDestructorCall(CGF, Dtor, DtorType, Ptr, DE,
900900
/*CallOrInvoke=*/nullptr);
901901
if (UseGlobalDelete)
@@ -1443,7 +1443,7 @@ MicrosoftCXXABI::getVirtualFunctionPrologueThisAdjustment(GlobalDecl GD) {
14431443

14441444
// There's no Dtor_Base in vftable but it shares the this adjustment with
14451445
// the deleting one, so look it up instead.
1446-
GD = GlobalDecl(DD, Dtor_Deleting);
1446+
GD = GlobalDecl(DD, Dtor_VectorDeleting);
14471447
}
14481448

14491449
MethodVFTableLocation ML =
@@ -2015,10 +2015,12 @@ llvm::Value *MicrosoftCXXABI::EmitVirtualDestructorCall(
20152015
llvm::FunctionType *Ty = CGF.CGM.getTypes().GetFunctionType(*FInfo);
20162016
CGCallee Callee = CGCallee::forVirtual(CE, GD, This, Ty);
20172017

2018+
bool UseGlobalDelete = D->isGlobalDelete();
2019+
bool CallDelete = !UseGlobalDelete;
20182020
ASTContext &Context = getContext();
20192021
llvm::Value *ImplicitParam = llvm::ConstantInt::get(
20202022
llvm::IntegerType::getInt32Ty(CGF.getLLVMContext()),
2021-
DtorType == Dtor_Deleting);
2023+
2 * (DtorType == Dtor_VectorDeleting) + CallDelete);
20222024

20232025
QualType ThisTy;
20242026
if (CE) {

0 commit comments

Comments
 (0)