PR4766: Don't pass -static to 'as' on x86_64 on Darwin.
Also, do pass -static even with -dynamic on i386.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79948 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index 9c8d940..1fb161a 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -1277,10 +1277,10 @@
CmdArgs.push_back(Args.MakeArgString(getToolChain().getArchName().c_str()));
CmdArgs.push_back("-force_cpusubtype_ALL");
- if ((Args.hasArg(options::OPT_mkernel) ||
+ if (getToolChain().getTriple().getArch() != llvm::Triple::x86_64 &&
+ (Args.hasArg(options::OPT_mkernel) ||
Args.hasArg(options::OPT_static) ||
- Args.hasArg(options::OPT_fapple_kext)) &&
- !Args.hasArg(options::OPT_dynamic))
+ Args.hasArg(options::OPT_fapple_kext)))
CmdArgs.push_back("-static");
Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
diff --git a/test/Driver/darwin-as.c b/test/Driver/darwin-as.c
new file mode 100644
index 0000000..24c7cd2
--- /dev/null
+++ b/test/Driver/darwin-as.c
@@ -0,0 +1,10 @@
+// RUN: clang -ccc-host-triple i386-apple-darwin10 -### -x assembler -c %s -static -dynamic 2>%t &&
+// RUN: FileCheck -check-prefix=STATIC_AND_DYNAMIC-32 --input-file %t %s
+
+// CHECK-STATIC_AND_DYNAMIC-32: as" "-arch" "i386" "-force_cpusubtype_ALL" "-static" "-o"
+
+// RUN: clang -ccc-host-triple x86_64-apple-darwin10 -### -x assembler -c %s -static 2>%t &&
+// RUN: FileCheck -check-prefix=STATIC-64 --input-file %t %s
+
+// CHECK-STATIC-64: as" "-arch" "x86_64" "-force_cpusubtype_ALL" "-o"
+