@@ -5378,11 +5378,33 @@ void CodeGenModule::EmitTentativeDefinition(const VarDecl *D) {
5378
5378
EmitGlobalVarDefinition (D);
5379
5379
}
5380
5380
5381
+ // Return a GlobalDecl. Use the base variants for destructors and constructors.
5382
+ static GlobalDecl getBaseVariantGlobalDecl (const NamedDecl *D) {
5383
+ if (auto const *CD = dyn_cast<const CXXConstructorDecl>(D))
5384
+ return GlobalDecl (CD, CXXCtorType::Ctor_Base);
5385
+ else if (auto const *DD = dyn_cast<const CXXDestructorDecl>(D))
5386
+ return GlobalDecl (DD, CXXDtorType::Dtor_Base);
5387
+ return GlobalDecl (D);
5388
+ }
5389
+
5381
5390
void CodeGenModule::EmitExternalDeclaration (const DeclaratorDecl *D) {
5382
- if (auto const *V = dyn_cast<const VarDecl>(D))
5383
- EmitExternalVarDeclaration (V);
5384
- if (auto const *FD = dyn_cast<const FunctionDecl>(D))
5385
- EmitExternalFunctionDeclaration (FD);
5391
+ CGDebugInfo *DI = getModuleDebugInfo ();
5392
+ if (!DI || !getCodeGenOpts ().hasReducedDebugInfo ())
5393
+ return ;
5394
+
5395
+ GlobalDecl GD = getBaseVariantGlobalDecl (D);
5396
+ if (!GD)
5397
+ return ;
5398
+
5399
+ llvm::Constant *Addr = GetAddrOfGlobal (GD)->stripPointerCasts ();
5400
+ if (const auto *VD = dyn_cast<VarDecl>(D)) {
5401
+ DI->EmitExternalVariable (
5402
+ cast<llvm::GlobalVariable>(Addr->stripPointerCasts ()), VD);
5403
+ } else if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
5404
+ llvm::Function *Fn = cast<llvm::Function>(Addr);
5405
+ if (!Fn->getSubprogram ())
5406
+ DI->EmitFunctionDecl (GD, FD->getLocation (), FD->getType (), Fn);
5407
+ }
5386
5408
}
5387
5409
5388
5410
CharUnits CodeGenModule::GetTargetTypeStoreSize (llvm::Type *Ty) const {
@@ -5825,30 +5847,6 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D,
5825
5847
DI->EmitGlobalVariable (GV, D);
5826
5848
}
5827
5849
5828
- void CodeGenModule::EmitExternalVarDeclaration (const VarDecl *D) {
5829
- if (CGDebugInfo *DI = getModuleDebugInfo ())
5830
- if (getCodeGenOpts ().hasReducedDebugInfo ()) {
5831
- QualType ASTTy = D->getType ();
5832
- llvm::Type *Ty = getTypes ().ConvertTypeForMem (D->getType ());
5833
- llvm::Constant *GV =
5834
- GetOrCreateLLVMGlobal (D->getName (), Ty, ASTTy.getAddressSpace (), D);
5835
- DI->EmitExternalVariable (
5836
- cast<llvm::GlobalVariable>(GV->stripPointerCasts ()), D);
5837
- }
5838
- }
5839
-
5840
- void CodeGenModule::EmitExternalFunctionDeclaration (const FunctionDecl *FD) {
5841
- if (CGDebugInfo *DI = getModuleDebugInfo ())
5842
- if (getCodeGenOpts ().hasReducedDebugInfo ()) {
5843
- auto *Ty = getTypes ().ConvertType (FD->getType ());
5844
- StringRef MangledName = getMangledName (FD);
5845
- auto *Fn = cast<llvm::Function>(
5846
- GetOrCreateLLVMFunction (MangledName, Ty, FD, /* ForVTable */ false ));
5847
- if (!Fn->getSubprogram ())
5848
- DI->EmitFunctionDecl (FD, FD->getLocation (), FD->getType (), Fn);
5849
- }
5850
- }
5851
-
5852
5850
static bool isVarDeclStrongDefinition (const ASTContext &Context,
5853
5851
CodeGenModule &CGM, const VarDecl *D,
5854
5852
bool NoCommon) {
0 commit comments