diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 94c48316add74..c3c0424cee562 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -5723,3 +5723,7 @@ llvm::DINode::DIFlags CGDebugInfo::getCallSiteRelatedAttrs() const { return llvm::DINode::FlagAllCallsDescribed; } + +void CGDebugInfo::retainPPType(llvm::DIType *Ty) { + DBuilder.retainType(Ty); +} diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h index 38e3fa5b2fa96..6db16d34b3e6a 100644 --- a/clang/lib/CodeGen/CGDebugInfo.h +++ b/clang/lib/CodeGen/CGDebugInfo.h @@ -383,6 +383,8 @@ class CGDebugInfo { void finalize(); + void retainPPType(llvm::DIType *Ty); + /// Remap a given path with the current debug prefix map std::string remapDIPath(StringRef) const; diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 3a4c542099281..532d44137461a 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -6091,9 +6091,11 @@ void CodeGenModule::HandlePPExtensionMethods( PtrToObjForGEP = MallocRes; } + bool SaveType = FSpec->getName().startswith("create_spec"); + PPExtInitTypeTagsRecursively(TypeNameExtracted, PtrToObjForGEP, - BB); + BB, SaveType); if (IsInitSpec) { llvm::ReturnInst::Create(getLLVMContext(), BB); @@ -6294,7 +6296,8 @@ template void CodeGenModule::PPExtInitTypeTagsRecursively( StringRef NameOfVariable, llvm::Value* PtrToObjForGEP, - TInsertPoint* IPoint) + TInsertPoint* IPoint, + bool SaveType) { auto* Ty = PPExtGetTypeByName(NameOfVariable); do { @@ -6302,6 +6305,18 @@ void CodeGenModule::PPExtInitTypeTagsRecursively( auto* GenRecTy = getTypes().ConvertTypeForMem(Qty); auto* RecordTy = Ty->getAsRecordDecl(); assert(RecordTy); + if (SaveType && RecordTy) { + if (CGDebugInfo *DI = getModuleDebugInfo()) { + if (RecordTy->isCompleteDefinition() && RecordTy->getIdentifier() && + RecordTy->getName().startswith("__pp_struct")) { + + QualType QT = getContext().getRecordType(RecordTy); + + auto *Ty = DI->getOrCreateRecordType(QT, RecordTy->getLocation()); + DI->retainPPType(Ty); + } + } + } llvm::APInt Apint0(32, 0); llvm::APInt Apint1(32, 1); auto* Number0 = diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h index e841381dff6a7..cf43df2214221 100644 --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -1592,7 +1592,8 @@ class CodeGenModule : public CodeGenTypeCache { template void PPExtInitTypeTagsRecursively(StringRef NameOfVariable, llvm::Value* PtrToObjForGEP, - TInsertPoint* IPoint); + TInsertPoint* IPoint, + bool SaveType = false); llvm::BasicBlock* InitPPHandlersArray(llvm::BasicBlock* BB,