From 2e58709f4488a9986f16bd6db8146fca235bda60 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Tue, 26 Apr 2016 23:37:38 +0000 Subject: [PATCH] Module debugging: Also correctly handle typedef'd foward-declared members. Thanks again to Richard Smith for pointing this out. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@267630 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGDebugInfo.cpp | 13 ++++++------- test/Modules/ExtDebugInfo.cpp | 13 ++++++++++++- test/Modules/Inputs/DebugCXX.h | 9 +++++---- test/Modules/ModuleDebugInfo.cpp | 4 ++++ 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index e275f060df..e794aeeb16 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -1520,13 +1520,12 @@ static bool isDefinedInClangModule(const RecordDecl *RD) { return false; if (!RD->isExternallyVisible() && RD->getName().empty()) return false; - if (auto *CTSD = dyn_cast(RD)) { - if (!CTSD->isCompleteDefinition()) - return false; - // Make sure the instantiation is actually in a module. - if (CTSD->field_begin() != CTSD->field_end()) - return CTSD->field_begin()->isFromASTFile(); - } + if (auto *CXXDecl = dyn_cast(RD)) + if (CXXDecl->getTemplateSpecializationKind() != TSK_Undeclared) + // Make sure the instantiation is actually in a module. + if (CXXDecl->field_begin() != CXXDecl->field_end()) + return CXXDecl->field_begin()->isFromASTFile(); + return true; } diff --git a/test/Modules/ExtDebugInfo.cpp b/test/Modules/ExtDebugInfo.cpp index 4760737bc4..dbf79f4ff1 100644 --- a/test/Modules/ExtDebugInfo.cpp +++ b/test/Modules/ExtDebugInfo.cpp @@ -28,6 +28,8 @@ using DebugCXX::Struct; Struct s; DebugCXX::Enum e; + +// Template instantiations. DebugCXX::Template implicitTemplate; DebugCXX::Template explicitTemplate; DebugCXX::FloatInstantiation typedefTemplate; @@ -51,13 +53,16 @@ TypedefFwdDeclTemplate tdfdt; InAnonymousNamespace anon; -// Forward-declared in the module. +// Types that are forward-declared in the module and defined here. struct PureFwdDecl { int i; }; PureFwdDecl definedLocally; struct Specialized::Member { int i; }; struct Specialized::Member definedLocally2; +template struct FwdDeclTemplateMember::Member { T t; }; +TypedefFwdDeclTemplateMember tdfdtm; + void foo() { anon.i = GlobalStruct.i = GlobalUnion.i = GlobalEnum; } @@ -150,6 +155,12 @@ void foo() { // CHECK-SAME: elements: // CHECK-SAME: identifier: "_ZTSN11SpecializedIiE6MemberE") +// This type is defined locally and forward-declared in the module. +// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "Member", +// CHECK-SAME: elements: +// CHECK-SAME: identifier: "_ZTSN21FwdDeclTemplateMemberIiE6MemberE") + + // CHECK: !DIGlobalVariable(name: "anon_enum", {{.*}}, type: ![[ANON_ENUM:[0-9]+]] // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, scope: ![[NS]], // CHECK-SAME: line: 16 diff --git a/test/Modules/Inputs/DebugCXX.h b/test/Modules/Inputs/DebugCXX.h index 9ae74dc688..793ad209f8 100644 --- a/test/Modules/Inputs/DebugCXX.h +++ b/test/Modules/Inputs/DebugCXX.h @@ -97,10 +97,11 @@ template class FwdDeclTemplate; typedef FwdDeclTemplate TypedefFwdDeclTemplate; // Member classes of class template specializations. -template struct Specialized { -}; +template struct Specialized {}; -template <> struct Specialized { -struct Member;// { int i; }; +template <> struct Specialized { + struct Member; }; +template struct FwdDeclTemplateMember { struct Member; }; +typedef FwdDeclTemplateMember::Member TypedefFwdDeclTemplateMember; diff --git a/test/Modules/ModuleDebugInfo.cpp b/test/Modules/ModuleDebugInfo.cpp index 4502373630..998d36327e 100644 --- a/test/Modules/ModuleDebugInfo.cpp +++ b/test/Modules/ModuleDebugInfo.cpp @@ -130,5 +130,9 @@ // CHECK-SAME: flags: DIFlagFwdDecl // CHECK-SAME: identifier: "_ZTS15FwdDeclTemplateIiE") +// Forward-declared member of a template. +// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "Member", +// CHECK-SAME: flags: DIFlagFwdDecl +// CHECK-SAME: identifier: "_ZTSN21FwdDeclTemplateMemberIiE6MemberE") // CHECK-NEG-NOT: !DICompositeType(tag: DW_TAG_structure_type, name: "PureForwardDecl" -- 2.40.0