]> granicus.if.org Git - clang/commitdiff
Options: Use AliasArgs for -O -> -O2 translation.
authorHans Wennborg <hans@hanshq.net>
Thu, 1 Aug 2013 16:21:57 +0000 (16:21 +0000)
committerHans Wennborg <hans@hanshq.net>
Thu, 1 Aug 2013 16:21:57 +0000 (16:21 +0000)
This way we can do the translation in the .td file rather than manually.

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

include/clang/Driver/Options.td
lib/Driver/Tools.cpp
test/Driver/O.c [new file with mode: 0644]

index c03770095d822c1311fe0e08d8697e1c20d03756..e532b3751d33d3513345a2706637e6f2911cddeb 100644 (file)
@@ -220,6 +220,7 @@ def ObjCXX : Flag<["-"], "ObjC++">, Flags<[DriverOption]>,
 def ObjC : Flag<["-"], "ObjC">, Flags<[DriverOption]>,
   HelpText<"Treat source input files as Objective-C inputs">;
 def O : Joined<["-"], "O">, Group<O_Group>, Flags<[CC1Option]>;
+def O_flag : Flag<["-"], "O">, Flags<[CC1Option]>, Alias<O>, AliasArgs<["2"]>;
 def Ofast : Joined<["-"], "Ofast">, Group<O_Group>, Flags<[CC1Option]>;
 def P : Flag<["-"], "P">, Flags<[CC1Option]>,
   HelpText<"Disable linemarker output in -E mode">;
index bc003facba02e0d497a31d9677a88ce41e01fba5..20dbaaddb0cc03d3e5987b460461716d7a462ff8 100644 (file)
@@ -2705,14 +2705,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
   // preprocessed inputs and configure concludes that -fPIC is not supported.
   Args.ClaimAllArgs(options::OPT_D);
 
-  // Manually translate -O to -O2 and -O4 to -O3; let clang reject
-  // others.
+  // Manually translate -O4 to -O3; let clang reject others.
   if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
     if (A->getOption().matches(options::OPT_O4))
       CmdArgs.push_back("-O3");
-    else if (A->getOption().matches(options::OPT_O) &&
-             A->getValue()[0] == '\0')
-      CmdArgs.push_back("-O2");
     else
       A->render(Args, CmdArgs);
   }
diff --git a/test/Driver/O.c b/test/Driver/O.c
new file mode 100644 (file)
index 0000000..a7dedc8
--- /dev/null
@@ -0,0 +1,10 @@
+// Test that we parse and translate the -O option correctly.
+
+// RUN: %clang -O -### %s 2>&1 | FileCheck -check-prefix=CHECK-O %s
+// CHECK-O: -O2
+
+// RUN: %clang -O0 -### %s 2>&1 | FileCheck -check-prefix=CHECK-O0 %s
+// CHECK-O0: -O0
+
+// RUN: %clang -O1 -### %s 2>&1 | FileCheck -check-prefix=CHECK-O1 %s
+// CHECK-O1: -O1