diff --git a/clang/include/clang/AST/ExternalASTSource.h b/clang/include/clang/AST/ExternalASTSource.h index fa0ea875bbec..81cf631c7a4a 100644 --- a/clang/include/clang/AST/ExternalASTSource.h +++ b/clang/include/clang/AST/ExternalASTSource.h @@ -159,7 +159,7 @@ public: : PCHModuleName(std::move(Name)), Path(std::move(Path)), ASTFile(std::move(ASTFile)), Signature(Signature){}; ASTSourceDescriptor(const Module &M); - std::string getFullModuleName() const; + std::string getModuleName() const; StringRef getPath() const { return Path; } StringRef getASTFile() const { return ASTFile; } uint64_t getSignature() const { return Signature; } diff --git a/clang/lib/AST/ExternalASTSource.cpp b/clang/lib/AST/ExternalASTSource.cpp index f3b15fc58c82..e3de8c5fefa2 100644 --- a/clang/lib/AST/ExternalASTSource.cpp +++ b/clang/lib/AST/ExternalASTSource.cpp @@ -36,9 +36,9 @@ ExternalASTSource::ASTSourceDescriptor::ASTSourceDescriptor(const Module &M) ASTFile = File->getName(); } -std::string ExternalASTSource::ASTSourceDescriptor::getFullModuleName() const { +std::string ExternalASTSource::ASTSourceDescriptor::getModuleName() const { if (ClangModule) - return ClangModule->getFullModuleName(); + return ClangModule->Name; else return PCHModuleName; } diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index d8879cc6f10c..c2cc49a0c5ed 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -1707,18 +1707,23 @@ CGDebugInfo::getOrCreateModuleRef(ExternalASTSource::ASTSourceDescriptor Mod, } } - std::string FullModuleName = Mod.getFullModuleName(); - if (CreateSkeletonCU) { + bool IsRootModule = M ? !M->Parent : true; + if (CreateSkeletonCU && IsRootModule) { llvm::DIBuilder DIB(CGM.getModule()); - DIB.createCompileUnit(TheCU->getSourceLanguage(), FullModuleName, + DIB.createCompileUnit(TheCU->getSourceLanguage(), Mod.getModuleName(), Mod.getPath(), TheCU->getProducer(), true, StringRef(), 0, Mod.getASTFile(), llvm::DIBuilder::FullDebug, Mod.getSignature()); DIB.finalize(); } + llvm::DIModule *Parent = + IsRootModule ? nullptr + : getOrCreateModuleRef( + ExternalASTSource::ASTSourceDescriptor(*M->Parent), + CreateSkeletonCU); llvm::DIModule *DIMod = - DBuilder.createModule(TheCU, FullModuleName, ConfigMacros, Mod.getPath(), - CGM.getHeaderSearchOpts().Sysroot); + DBuilder.createModule(Parent, Mod.getModuleName(), ConfigMacros, + Mod.getPath(), CGM.getHeaderSearchOpts().Sysroot); ModRef.reset(DIMod); return DIMod; } diff --git a/clang/test/Modules/DebugInfoSubmoduleImport.c b/clang/test/Modules/DebugInfoSubmoduleImport.c new file mode 100644 index 000000000000..d5be3ca1462b --- /dev/null +++ b/clang/test/Modules/DebugInfoSubmoduleImport.c @@ -0,0 +1,15 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -fmodules -fmodule-format=obj -g -dwarf-ext-refs \ +// RUN: -fimplicit-module-maps -x c -fmodules-cache-path=%t -I %S/Inputs \ +// RUN: %s -emit-llvm -o - | FileCheck %s +#include "DebugSubmoduleA.h" +#include "DebugSubmoduleB.h" + +// CHECK: !DICompileUnit +// CHECK-NOT: !DICompileUnit +// CHECK: !DIModule(scope: ![[PARENT:.*]], name: "DebugSubmoduleA" +// CHECK: [[PARENT]] = !DIModule(scope: null, name: "DebugSubmodules" +// CHECK: !DIModule(scope: ![[PARENT]], name: "DebugSubmoduleB" +// CHECK: !DICompileUnit({{.*}}splitDebugFilename: {{.*}}DebugSubmodules +// CHECK-SAME: dwoId: +// CHECK-NOT: !DICompileUnit diff --git a/clang/test/Modules/DebugInfoSubmodules.c b/clang/test/Modules/DebugInfoSubmodules.c index fdcff07c1226..8987a57b1296 100644 --- a/clang/test/Modules/DebugInfoSubmodules.c +++ b/clang/test/Modules/DebugInfoSubmodules.c @@ -1,16 +1,18 @@ // RUN: rm -rf %t // RUN: %clang_cc1 -fmodules -fmodule-format=obj -g -dwarf-ext-refs \ // RUN: -fimplicit-module-maps -x c -fmodules-cache-path=%t -I %S/Inputs \ -// RUN: %s -mllvm -debug-only=pchcontainer 2>&1 | FileCheck %s +// RUN: %s -mllvm -debug-only=pchcontainer -emit-llvm -o %t.ll \ +// RUN: 2>&1 | FileCheck %s // REQUIRES: asserts #include "DebugSubmoduleA.h" // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "A", // CHECK-SAME: scope: ![[SUBMODULEA:[0-9]+]] -// CHECK: ![[SUBMODULEA]] = !DIModule( -// CHECK-SAME: name: "DebugSubmodules.DebugSubmoduleA", +// CHECK: ![[SUBMODULEA]] = !DIModule(scope: ![[PARENT:[0-9]+]], +// CHECK-SAME: name: "DebugSubmoduleA", +// CHECK: ![[PARENT]] = !DIModule(scope: null, name: "DebugSubmodules" // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "B", // CHECK-SAME: scope: ![[SUBMODULEB:[0-9]+]] -// CHECK: ![[SUBMODULEB]] = !DIModule( -// CHECK-SAME: name: "DebugSubmodules.DebugSubmoduleB", +// CHECK: ![[SUBMODULEB]] = !DIModule(scope: ![[PARENT]], +// CHECK-SAME: name: "DebugSubmoduleB",