[clang] Fix scope of typedefs present inside a template class (PR #146729)

David Blaikie via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 5 13:09:43 PDT 2025


================
@@ -4189,8 +4189,13 @@ llvm::DICompositeType *CGDebugInfo::CreateLimitedType(const RecordType *Ty) {
         llvm::MDNode::replaceWithDistinct(llvm::TempDICompositeType(RealDecl));
     break;
   }
-
-  RegionMap[Ty->getDecl()].reset(RealDecl);
+  if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(Ty->getDecl())) {
+    CXXRecordDecl *TemplateDecl =
+        CTSD->getSpecializedTemplate()->getTemplatedDecl();
+    RegionMap[TemplateDecl].reset(RealDecl);
+  } else {
+    RegionMap[Ty->getDecl()].reset(RealDecl);
+  }
----------------
dwblaikie wrote:

But I'm still a bit confused by this code in general - the `templated decl` is the generic thing, right? But DWARF doesn't describe generic things, so we'd want to put these nested elements in specific instantiations... 

(presumably if this patch is the right path forward, we'd need something similar for the `RegionMap.erase(Ty->getDecl());` ? (or perhapps that's matched up with some other mutation))

https://github.com/llvm/llvm-project/pull/146729


More information about the cfe-commits mailing list