From 9345c88c02f06e0b4cc72a054498450835118cde Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Mon, 21 Sep 2015 17:48:37 +0000 Subject: [PATCH] Debug Info: When building a module, emit skeleton CUs for imported modules. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@248184 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGDebugInfo.cpp | 17 ++++++++--------- .../ObjectFilePCHContainerOperations.cpp | 7 +++++++ test/Modules/DebugInfoTransitiveImport.m | 15 +++++++++++++++ 3 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 test/Modules/DebugInfoTransitiveImport.m diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 6af8d6626b..ae1f5e7ecf 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -2161,7 +2161,14 @@ ObjCInterfaceDecl *CGDebugInfo::getObjCInterfaceDecl(QualType Ty) { llvm::DIModule *CGDebugInfo::getParentModuleOrNull(const Decl *D) { ExternalASTSource::ASTSourceDescriptor Info; - if (ClangModuleMap) { + if (DebugTypeExtRefs && D->isFromASTFile()) { + // Record a reference to an imported clang module or precompiled header. + auto *Reader = CGM.getContext().getExternalSource(); + auto Idx = D->getOwningModuleID(); + auto Info = Reader->getSourceDescriptor(Idx); + if (Info) + return getOrCreateModuleRef(*Info, /*SkeletonCU=*/true); + } else if (ClangModuleMap) { // We are building a clang module or a precompiled header. // // TODO: When D is a CXXRecordDecl or a C++ Enum, the ODR applies @@ -2179,14 +2186,6 @@ llvm::DIModule *CGDebugInfo::getParentModuleOrNull(const Decl *D) { } } - if (DebugTypeExtRefs && D->isFromASTFile()) { - // Record a reference to an imported clang module or precompiled header. - auto *Reader = CGM.getContext().getExternalSource(); - auto Idx = D->getOwningModuleID(); - auto Info = Reader->getSourceDescriptor(Idx); - if (Info) - return getOrCreateModuleRef(*Info, /*SkeletonCU=*/true); - } return nullptr; } diff --git a/lib/CodeGen/ObjectFilePCHContainerOperations.cpp b/lib/CodeGen/ObjectFilePCHContainerOperations.cpp index 1673340a49..310e374e34 100644 --- a/lib/CodeGen/ObjectFilePCHContainerOperations.cpp +++ b/lib/CodeGen/ObjectFilePCHContainerOperations.cpp @@ -67,6 +67,13 @@ class PCHContainerGenerator : public ASTConsumer { return !Ty->isDependentType() && !Ty->isUndeducedType(); } + bool VisitImportDecl(ImportDecl *D) { + auto *Import = cast(D); + if (!Import->getImportedOwningModule()) + DI.EmitImportDecl(*Import); + return true; + } + bool VisitTypeDecl(TypeDecl *D) { QualType QualTy = Ctx.getTypeDeclType(D); if (!QualTy.isNull() && CanRepresent(QualTy.getTypePtr())) diff --git a/test/Modules/DebugInfoTransitiveImport.m b/test/Modules/DebugInfoTransitiveImport.m new file mode 100644 index 0000000000..c6828244d2 --- /dev/null +++ b/test/Modules/DebugInfoTransitiveImport.m @@ -0,0 +1,15 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -fmodules -fmodule-format=obj -g -dwarf-ext-refs \ +// RUN: -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs \ +// RUN: %s -mllvm -debug-only=pchcontainer 2>&1 | FileCheck %s +// REQUIRES: asserts + +@import diamond_left; + +// CHECK: ![[TOP_DEF:.*]] = distinct !DICompileUnit({{.*}}diamond_top +// CHECK: ![[LEFT_DEF:.*]] = distinct !DICompileUnit({{.*}}diamond_left +// CHECK: !DIImportedEntity(tag: DW_TAG_imported_declaration, +// CHECK-SAME: entity: ![[MODULE:.*]], line: 3) +// CHECK: ![[MODULE]] = !DIModule(scope: null, name: "diamond_top" +// CHECK: ![[TOP_SKEL_CU:.*]] = distinct !DICompileUnit({{.*}}diamond_top{{.*}}dwoId: + -- 2.40.0