diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index fe1dd15c6f885..6fe54f65656fc 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -229,6 +229,7 @@ Bug Fixes in This Version cast chain. (#GH149967). - Fixed a crash with incompatible pointer to integer conversions in designated initializers involving string literals. (#GH154046) +- Fixed scope of typedefs present inside a template class. (#GH91451) Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 994bdbdae860f..c44fea3e6383d 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -4184,7 +4184,14 @@ llvm::DICompositeType *CGDebugInfo::CreateLimitedType(const RecordType *Ty) { break; } - RegionMap[RD].reset(RealDecl); + if (auto *CTSD = + dyn_cast(Ty->getOriginalDecl())) { + CXXRecordDecl *TemplateDecl = + CTSD->getSpecializedTemplate()->getTemplatedDecl(); + RegionMap[TemplateDecl].reset(RealDecl); + } else { + RegionMap[RD].reset(RealDecl); + } TypeCache[QualType(Ty, 0).getAsOpaquePtr()].reset(RealDecl); if (const auto *TSpecial = dyn_cast(RD)) diff --git a/clang/test/DebugInfo/CXX/dependent-template-type-scope.cpp b/clang/test/DebugInfo/CXX/dependent-template-type-scope.cpp new file mode 100644 index 0000000000000..25a4d8741b01e --- /dev/null +++ b/clang/test/DebugInfo/CXX/dependent-template-type-scope.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -debug-info-kind=standalone -o - %s | FileCheck %s + +template +struct Y { + typedef int outside; + outside o; +}; + +Y<> y; + +// CHECK: ![[Y:.*]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Y", {{.*}}identifier: "_ZTS1YIiE") +// CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "outside", scope: ![[Y]],