]> granicus.if.org Git - clang/commitdiff
Debug Info: When building a module, emit skeleton CUs for imported modules.
authorAdrian Prantl <aprantl@apple.com>
Mon, 21 Sep 2015 17:48:37 +0000 (17:48 +0000)
committerAdrian Prantl <aprantl@apple.com>
Mon, 21 Sep 2015 17:48:37 +0000 (17:48 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@248184 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGDebugInfo.cpp
lib/CodeGen/ObjectFilePCHContainerOperations.cpp
test/Modules/DebugInfoTransitiveImport.m [new file with mode: 0644]

index 6af8d6626b43b12e72e66525e862689f1bd18640..ae1f5e7ecfad0751e3b5da78e2b518729c87b6d4 100644 (file)
@@ -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;
 }
 
index 1673340a495cb801df4410ab4095301bcc383900..310e374e348da0c8c48cefbd7c7abea4a0a3f875 100644 (file)
@@ -67,6 +67,13 @@ class PCHContainerGenerator : public ASTConsumer {
       return !Ty->isDependentType() && !Ty->isUndeducedType();
     }
 
+    bool VisitImportDecl(ImportDecl *D) {
+      auto *Import = cast<ImportDecl>(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 (file)
index 0000000..c682824
--- /dev/null
@@ -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:
+