@@ -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.
207207void 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
236227llvm::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>(
0 commit comments