Options: Use AliasArgs for -O -> -O2 translation.

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
diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td
index c037700..e532b37 100644
--- a/include/clang/Driver/Options.td
+++ b/include/clang/Driver/Options.td
@@ -220,6 +220,7 @@
 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">;
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index bc003fa..20dbaad 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -2705,14 +2705,10 @@
   // 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
index 0000000..a7dedc8
--- /dev/null
+++ b/test/Driver/O.c
@@ -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