From 7cd89c529e57579d02c0192eea1d4720fcacdd5f Mon Sep 17 00:00:00 2001 From: mulyukovaaa Date: Fri, 2 May 2025 17:34:09 +0300 Subject: [PATCH 1/3] add public retain type --- clang/lib/CodeGen/CGDebugInfo.cpp | 4 ++++ clang/lib/CodeGen/CGDebugInfo.h | 2 ++ 2 files changed, 6 insertions(+) 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; From dc84729b538370113f036d97b418dafa44b9c1ca Mon Sep 17 00:00:00 2001 From: mulyukovaaa Date: Fri, 2 May 2025 17:45:26 +0300 Subject: [PATCH 2/3] add debug info for struct_X_Y --- clang/lib/CodeGen/CGDebugInfo.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index c3c0424cee562..da3ff184fea8f 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -5678,6 +5678,24 @@ void CGDebugInfo::finalize() { if (auto MD = TypeCache[RT]) DBuilder.retainType(cast(MD)); + TranslationUnitDecl *TU = CGM.getContext().getTranslationUnitDecl(); + + for (Decl *D : TU->decls()) { + auto *RD = dyn_cast(D); + if (!RD || !RD->getIdentifier() || !RD->isCompleteDefinition()) + continue; + + StringRef Name = RD->getName(); + if (!Name.startswith("__pp_struct")) + continue; + + QualType QT = CGM.getContext().getRecordType(RD); + + auto *Ty = getOrCreateType(QT, getOrCreateFile(RD->getLocation())); + if (Ty) + DBuilder.retainType(Ty); + } + DBuilder.finalize(); } From 902b48fc8fb1086aacfc5851502064a0d73d6326 Mon Sep 17 00:00:00 2001 From: mulyukovaaa Date: Fri, 2 May 2025 18:34:28 +0300 Subject: [PATCH 3/3] change location "add debug type" --- clang/lib/CodeGen/CGDebugInfo.cpp | 18 ------------------ clang/lib/CodeGen/CodeGenModule.cpp | 19 +++++++++++++++++-- clang/lib/CodeGen/CodeGenModule.h | 3 ++- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index da3ff184fea8f..c3c0424cee562 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -5678,24 +5678,6 @@ void CGDebugInfo::finalize() { if (auto MD = TypeCache[RT]) DBuilder.retainType(cast(MD)); - TranslationUnitDecl *TU = CGM.getContext().getTranslationUnitDecl(); - - for (Decl *D : TU->decls()) { - auto *RD = dyn_cast(D); - if (!RD || !RD->getIdentifier() || !RD->isCompleteDefinition()) - continue; - - StringRef Name = RD->getName(); - if (!Name.startswith("__pp_struct")) - continue; - - QualType QT = CGM.getContext().getRecordType(RD); - - auto *Ty = getOrCreateType(QT, getOrCreateFile(RD->getLocation())); - if (Ty) - DBuilder.retainType(Ty); - } - DBuilder.finalize(); } 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,