dsymutil: Fix the condition to distinguish module imports form definitions.

llvm-svn: 248512
diff --git a/llvm/test/tools/dsymutil/Inputs/submodules/1.o b/llvm/test/tools/dsymutil/Inputs/submodules/1.o
new file mode 100644
index 0000000..f95b70c
--- /dev/null
+++ b/llvm/test/tools/dsymutil/Inputs/submodules/1.o
Binary files differ
diff --git a/llvm/test/tools/dsymutil/Inputs/submodules/Parent.pcm b/llvm/test/tools/dsymutil/Inputs/submodules/Parent.pcm
new file mode 100644
index 0000000..dca33af
--- /dev/null
+++ b/llvm/test/tools/dsymutil/Inputs/submodules/Parent.pcm
Binary files differ
diff --git a/llvm/test/tools/dsymutil/X86/submodules.m b/llvm/test/tools/dsymutil/X86/submodules.m
new file mode 100644
index 0000000..64efc2f
--- /dev/null
+++ b/llvm/test/tools/dsymutil/X86/submodules.m
@@ -0,0 +1,40 @@
+/* Compile with:
+   cat >modules.modulemap <<EOF
+   module Parent {
+     module Child {
+       header "Child.h"
+     }
+   }
+EOF
+   clang -D CHILD_H -E -o Child.h submodules.m
+   clang -cc1 -emit-obj -fmodules -fmodule-map-file=modules.modulemap \
+     -fmodule-format=obj -g -dwarf-ext-refs -fmodules-cache-path=. \
+     -fdisable-module-hash submodules.m -o 1.o
+*/
+
+// RUN: llvm-dsymutil -f -oso-prepend-path=%p/../Inputs/submodules \
+// RUN:   -y %p/dummy-debug-map.map -o - \
+// RUN:     | llvm-dwarfdump --debug-dump=info - | FileCheck %s
+
+// ---------------------------------------------------------------------
+#ifdef CHILD_H
+// ---------------------------------------------------------------------
+// CHECK:            DW_TAG_compile_unit
+// CHECK-NOT:        DW_TAG
+// CHECK:              DW_TAG_module
+// CHECK-NEXT:           DW_AT_name{{.*}}"Parent"
+// CHECK:                DW_TAG_module
+// CHECK-NEXT:             DW_AT_name{{.*}}"Child"
+// CHECK:                  DW_TAG_structure_type
+// CHECK-NOT:                DW_TAG
+// CHECK:                    DW_AT_name {{.*}}"PruneMeNot"
+
+struct PruneMeNot;
+
+// ---------------------------------------------------------------------
+#else
+// ---------------------------------------------------------------------
+
+@import Parent.Child;
+int main(int argc, char **argv) { return 0; }
+#endif
diff --git a/llvm/tools/dsymutil/DwarfLinker.cpp b/llvm/tools/dsymutil/DwarfLinker.cpp
index 1aa15c5..8489189 100644
--- a/llvm/tools/dsymutil/DwarfLinker.cpp
+++ b/llvm/tools/dsymutil/DwarfLinker.cpp
@@ -1780,7 +1780,7 @@
   //   definitions match)."
   //
   // We treat non-C++ modules like namespaces for this reason.
-  if (DIE->getTag() == dwarf::DW_TAG_module &&
+  if (DIE->getTag() == dwarf::DW_TAG_module && ParentIdx == 0 &&
       DIE->getAttributeValueAsString(&CU.getOrigUnit(), dwarf::DW_AT_name,
                                      "") != CU.getClangModuleName()) {
     InImportedModule = true;