]> granicus.if.org Git - clang/commitdiff
Invalid O levels on the command line no longer have a confusing error.
authorAaron Ballman <aaron@aaronballman.com>
Mon, 6 Feb 2012 00:40:31 +0000 (00:40 +0000)
committerAaron Ballman <aaron@aaronballman.com>
Mon, 6 Feb 2012 00:40:31 +0000 (00:40 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149852 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/CompilerInvocation.cpp
test/Driver/invalid-o-level.c [new file with mode: 0644]

index 7876bcb24305f1956950b803862bded2291f1784..8417aa48c077ae01e875fd1509d566676556d23b 100644 (file)
@@ -1076,13 +1076,14 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
   using namespace cc1options;
   bool Success = true;
 
-  Opts.OptimizationLevel = getOptimizationLevel(Args, IK, Diags);
-  if (Opts.OptimizationLevel > 3) {
+  unsigned OptLevel = getOptimizationLevel(Args, IK, Diags);
+  if (OptLevel > 3) {
     Diags.Report(diag::err_drv_invalid_value)
-      << Args.getLastArg(OPT_O)->getAsString(Args) << Opts.OptimizationLevel;
-    Opts.OptimizationLevel = 3;
+      << Args.getLastArg(OPT_O)->getAsString(Args) << OptLevel;
+    OptLevel = 3;
     Success = false;
   }
+  Opts.OptimizationLevel = OptLevel;
 
   // We must always run at least the always inlining pass.
   Opts.Inlining = (Opts.OptimizationLevel > 1) ? CodeGenOptions::NormalInlining
diff --git a/test/Driver/invalid-o-level.c b/test/Driver/invalid-o-level.c
new file mode 100644 (file)
index 0000000..d5242c7
--- /dev/null
@@ -0,0 +1,4 @@
+// RUN: not %clang_cc1 %s -O900 2> %t.log
+// RUN: FileCheck %s -input-file=%t.log
+
+// CHECK: invalid value '900' in '-O900'