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

via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 20 09:50:23 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);
+  }
----------------
ykhatav wrote:

I don't think it affects typedefs scoped in partial template specialization since the Typedef Context ends up being partial class specialization instead of the record decl or the Class specialization stored in the RegionMap:
`
```
0x00000057:   DW_TAG_structure_type
                DW_AT_calling_convention        (DW_CC_pass_by_value)
                DW_AT_name      ("Y<Foo<int> >")
                DW_AT_byte_size (0x04)
                DW_AT_decl_file ("/")
                DW_AT_decl_line (15)

0x0000005d:     DW_TAG_template_type_parameter
                  DW_AT_type    (0x0000006d "Foo<int>")
                  DW_AT_name    ("T")

0x00000063:     DW_TAG_member
                  DW_AT_name    ("o")
                  DW_AT_type    (0x0000006f "outside")
                  DW_AT_decl_file       ("/")
                  DW_AT_decl_line       (17)
                  DW_AT_data_member_location    (0x00)

0x0000006c:     NULL

0x0000006d:   DW_TAG_structure_type
                DW_AT_name      ("Foo<int>")
                DW_AT_declaration       (true)

0x0000006f:   DW_TAG_typedef
                DW_AT_type      (0x00000048 "int")
                DW_AT_name      ("outside")
                DW_AT_decl_file ("/")
                DW_AT_decl_line (16)

`
```
I think we should be able to address this with the other approach you suggested. 

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


More information about the cfe-commits mailing list