From 90199139dcd767a3bfc488590a8b27145bce7766 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Tue, 16 May 2017 23:46:10 +0000 Subject: [PATCH] Fix scope of namespaced DISubprograms when the function definition is out-of-line. This fixes a regression introduced in r302915. Using the lexical decl context is not necessary here for what r302915 wast trying to achieve. Not canonicalizing the NamespaceDecl in getOrCreateNamespace is suficient. rdar://problem/29339538 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@303222 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGDebugInfo.cpp | 2 +- test/CodeGenCXX/debug-info-namespace.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 9d77c61bd5..bf178dd7fd 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -2860,7 +2860,7 @@ void CGDebugInfo::collectFunctionDeclProps(GlobalDecl GD, llvm::DIFile *Unit, if (DebugKind >= codegenoptions::LimitedDebugInfo) { if (const NamespaceDecl *NSDecl = - dyn_cast_or_null(FD->getLexicalDeclContext())) + dyn_cast_or_null(FD->getDeclContext())) FDContext = getOrCreateNamespace(NSDecl); else if (const RecordDecl *RDecl = dyn_cast_or_null(FD->getDeclContext())) { diff --git a/test/CodeGenCXX/debug-info-namespace.cpp b/test/CodeGenCXX/debug-info-namespace.cpp index 5b81197671..95857e3390 100644 --- a/test/CodeGenCXX/debug-info-namespace.cpp +++ b/test/CodeGenCXX/debug-info-namespace.cpp @@ -60,6 +60,10 @@ void B::func_fwd() { anonymous = 0; } +namespace C { + void c(); +} +void C::c() {} // This should work even if 'i' and 'func' were declarations & not definitions, // but it doesn't yet. @@ -114,6 +118,8 @@ void B::func_fwd() { // CHECK: [[M16]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[FUNC_FWD:![0-9]+]] // CHECK: [[FUNC_FWD]] = distinct !DISubprogram(name: "func_fwd",{{.*}} line: 53,{{.*}} isDefinition: true // CHECK: [[M17]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[CTXT]], entity: [[I]] +// CHECK: distinct !DISubprogram(name: "c",{{.*}}, scope: ![[C:[0-9]+]],{{.*}}, line: 60,{{.*}} isDefinition: true +// CHECK: ![[C]] = !DINamespace(name: "C", // CHECK-GMLT: [[CU:![0-9]+]] = distinct !DICompileUnit( // CHECK-GMLT-SAME: emissionKind: LineTablesOnly, -- 2.40.0