From 5704d34444ecd7e1baa90026fb36c47207e0a3b7 Mon Sep 17 00:00:00 2001
From: Eric Christopher <echristo@gmail.com>
Date: Fri, 22 Feb 2013 01:33:46 +0000
Subject: [PATCH] Make sure we only use the output file as a base for debug
 splitting if we're compiling.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175851 91177308-0d34-0410-b5e6-96231b3b80d8
---
 lib/Driver/Tools.cpp      | 2 +-
 test/Driver/split-debug.c | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index e830bdcc9c3..ebbabcfdf9c 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -1723,7 +1723,7 @@ void Clang::SplitDebugInfo(Compilation &C, const JobAction &JA,
   // Add an output for the extract.
   Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o);
   const char *OutFile;
-  if (FinalOutput) {
+  if (FinalOutput && C.getArgs().hasArg(options::OPT_c)) {
     SmallString<128> T(FinalOutput->getValue());
     llvm::sys::path::replace_extension(T, "dwo");
     OutFile = Args.MakeArgString(T);
diff --git a/test/Driver/split-debug.c b/test/Driver/split-debug.c
index fb01953b0d6..5c77e6e98cf 100644
--- a/test/Driver/split-debug.c
+++ b/test/Driver/split-debug.c
@@ -12,3 +12,9 @@
 // RUN: FileCheck -check-prefix=CHECK-NO-ACTIONS < %t %s
 //
 // CHECK-NO-ACTIONS-NOT: -split-dwarf
+
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -o Bad.x -### %s 2> %t
+// RUN: FileCheck -check-prefix=CHECK-BAD < %t %s
+//
+// CHECK-BAD-NOT: "Bad.dwo"
-- 
GitLab