From 42829a5316b507a78f4c9d53890718bf6bf7b95e Mon Sep 17 00:00:00 2001
From: Frederic Riss <friss@apple.com>
Date: Mon, 31 Aug 2015 05:16:35 +0000
Subject: [PATCH] [dsymutil] Do not mistakenly reuse the current object file
 when the next one isn't found.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@246412 91177308-0d34-0410-b5e6-96231b3b80d8
---
 test/tools/dsymutil/X86/empty_range.s | 4 ++++
 tools/dsymutil/DwarfLinker.cpp        | 4 +++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/test/tools/dsymutil/X86/empty_range.s b/test/tools/dsymutil/X86/empty_range.s
index 5c8ae6a1826..dfe734f1b2b 100644
--- a/test/tools/dsymutil/X86/empty_range.s
+++ b/test/tools/dsymutil/X86/empty_range.s
@@ -55,3 +55,7 @@ Ldebug_range:
 # CHECK-NEXT:      DW_AT_low_pc{{.*}}(0x0000000000010000)
 # CHECK-NEXT:      DW_AT_ranges{{.*}}(0x00000000)
 
+# There was a bug that would use the currently active object file when a
+# debug map object isn't found. Check that we only linked one file.
+# CHECK-NOT: DW_TAG_compile_unit
+
diff --git a/tools/dsymutil/DwarfLinker.cpp b/tools/dsymutil/DwarfLinker.cpp
index f3e48f5033e..ed06dba8ab3 100644
--- a/tools/dsymutil/DwarfLinker.cpp
+++ b/tools/dsymutil/DwarfLinker.cpp
@@ -2942,8 +2942,10 @@ DwarfLinker::loadObject(BinaryHolder &BinaryHolder, DebugMapObject &Obj,
                         const DebugMap &Map) {
   auto ErrOrObjs =
       BinaryHolder.GetObjectFiles(Obj.getObjectFilename(), Obj.getTimestamp());
-  if (std::error_code EC = ErrOrObjs.getError())
+  if (std::error_code EC = ErrOrObjs.getError()) {
     reportWarning(Twine(Obj.getObjectFilename()) + ": " + EC.message());
+    return EC;
+  }
   auto ErrOrObj = BinaryHolder.Get(Map.getTriple());
   if (std::error_code EC = ErrOrObj.getError())
     reportWarning(Twine(Obj.getObjectFilename()) + ": " + EC.message());
-- 
2.34.1