]> granicus.if.org Git - clang/commitdiff
clang-cl: fix passing optimization level to cl.exe in /fallback mode
authorHans Wennborg <hans@hanshq.net>
Tue, 24 Sep 2013 18:17:21 +0000 (18:17 +0000)
committerHans Wennborg <hans@hanshq.net>
Tue, 24 Sep 2013 18:17:21 +0000 (18:17 +0000)
We were previously mostly passing it through, but -O0 and -O3 are not valid
options to cl.exe.

We should translate -O0 to /Od and -O3 to /Ox. -O{1,2,s} get passed through.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191323 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/Tools.cpp
test/Driver/cl-fallback.c

index 5b96120df9775d9356ec5d2d90c4ba2717491eb5..e5f2681f7b36b0c4f91bf87e68a3e39c2d6d76a0 100644 (file)
@@ -6712,7 +6712,19 @@ Command *visualstudio::Compile::GetCommand(Compilation &C, const JobAction &JA,
   // These are spelled the same way in clang and cl.exe,.
   Args.AddAllArgs(CmdArgs, options::OPT_D, options::OPT_U);
   Args.AddAllArgs(CmdArgs, options::OPT_I);
-  Args.AddLastArg(CmdArgs, options::OPT_O, options::OPT_O0);
+
+  // Optimization level.
+  if (Arg *A = Args.getLastArg(options::OPT_O, options::OPT_O0)) {
+    if (A->getOption().getID() == options::OPT_O0) {
+      CmdArgs.push_back("/Od");
+    } else {
+      StringRef OptLevel = A->getValue();
+      if (OptLevel == "1" || OptLevel == "2" || OptLevel == "s")
+        A->render(Args, CmdArgs);
+      else if (OptLevel == "3")
+        CmdArgs.push_back("/Ox");
+    }
+  }
 
   // Flags for which clang-cl have an alias.
   // FIXME: How can we ensure this stays in sync with relevant clang-cl options?
index 715686c6249d73b878ba27f6728aad1dc0d239f2..a80068bce4cc2ca4b837243b87e09aa5182cde00 100644 (file)
 // CHECK: "-D" "foo=bar"
 // CHECK: "-U" "baz"
 // CHECK: "-I" "foo"
-// CHECK: "-O3"
+// CHECK: "/Ox"
 // CHECK: "/GR-"
 // CHECK: "/LD"
 // CHECK: "/LDd"
 // CHECK: "/MT"
 // CHECK: "/Tc" "{{.*cl-fallback.c}}"
 // CHECK: "/Fo{{.*cl-fallback.*.obj}}"
+
+// RUN: %clang_cl /fallback /Od -### -- %s 2>&1 | FileCheck -check-prefix=O0 %s
+// O0: cl.exe
+// O0: "/Od"
+// RUN: %clang_cl /fallback /O1 -### -- %s 2>&1 | FileCheck -check-prefix=O1 %s
+// O1: cl.exe
+// O1: "-O1"
+// RUN: %clang_cl /fallback /O2 -### -- %s 2>&1 | FileCheck -check-prefix=O2 %s
+// O2: cl.exe
+// O2: "-O2"
+// RUN: %clang_cl /fallback /Os -### -- %s 2>&1 | FileCheck -check-prefix=Os %s
+// Os: cl.exe
+// Os: "-Os"
+// RUN: %clang_cl /fallback /Ox -### -- %s 2>&1 | FileCheck -check-prefix=Ox %s
+// Ox: cl.exe
+// Ox: "/Ox"