r224378 - Fix handling of invalid -O options.
Rafael Espindola
rafael.espindola at gmail.com
Tue Dec 16 13:57:03 PST 2014
Author: rafael
Date: Tue Dec 16 15:57:03 2014
New Revision: 224378
URL: http://llvm.org/viewvc/llvm-project?rev=224378&view=rev
Log:
Fix handling of invalid -O options.
We were checking the value after truncating it to a bitfield.
Thanks to Yunzhong Gao for noticing it.
Modified:
cfe/trunk/include/clang/Frontend/CodeGenOptions.def
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/test/Frontend/invalid-o-level.c
Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=224378&r1=224377&r2=224378&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def Tue Dec 16 15:57:03 2014
@@ -87,7 +87,7 @@ CODEGENOPT(NoZeroInitializedInBSS , 1, 0
ENUM_CODEGENOPT(ObjCDispatchMethod, ObjCDispatchMethodKind, 2, Legacy)
CODEGENOPT(OmitLeafFramePointer , 1, 0) ///< Set when -momit-leaf-frame-pointer is
///< enabled.
-VALUE_CODEGENOPT(OptimizationLevel, 3, 0) ///< The -O[0-4] option specified.
+VALUE_CODEGENOPT(OptimizationLevel, 2, 0) ///< The -O[0-3] option specified.
VALUE_CODEGENOPT(OptimizeSize, 2, 0) ///< If -Os (==1) or -Oz (==2) is specified.
CODEGENOPT(ProfileInstrGenerate , 1, 0) ///< Instrument code to generate
Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=224378&r1=224377&r2=224378&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Tue Dec 16 15:57:03 2014
@@ -330,15 +330,17 @@ static bool ParseCodeGenArgs(CodeGenOpti
using namespace options;
bool Success = true;
- Opts.OptimizationLevel = getOptimizationLevel(Args, IK, Diags);
+ unsigned OptimizationLevel = getOptimizationLevel(Args, IK, Diags);
// TODO: This could be done in Driver
unsigned MaxOptLevel = 3;
- if (Opts.OptimizationLevel > MaxOptLevel) {
- // If the optimization level is not supported, fall back on the default optimization
+ if (OptimizationLevel > MaxOptLevel) {
+ // If the optimization level is not supported, fall back on the default
+ // optimization
Diags.Report(diag::warn_drv_optimization_value)
<< Args.getLastArg(OPT_O)->getAsString(Args) << "-O" << MaxOptLevel;
- Opts.OptimizationLevel = MaxOptLevel;
+ OptimizationLevel = MaxOptLevel;
}
+ Opts.OptimizationLevel = OptimizationLevel;
// We must always run at least the always inlining pass.
Opts.setInlining(
Modified: cfe/trunk/test/Frontend/invalid-o-level.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/invalid-o-level.c?rev=224378&r1=224377&r2=224378&view=diff
==============================================================================
--- cfe/trunk/test/Frontend/invalid-o-level.c (original)
+++ cfe/trunk/test/Frontend/invalid-o-level.c Tue Dec 16 15:57:03 2014
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 %s -O900 -o /dev/null 2> %t.log
-// RUN: FileCheck %s -input-file=%t.log
+// RUN: %clang_cc1 %s -O900 -o /dev/null 2>&1 | FileCheck %s
-// CHECK: warning: optimization level '-O900' is not supported; using '-O3' instead
+// RUN: %clang_cc1 %s -O8 -o /dev/null 2>&1 | FileCheck %s
+
+// CHECK: warning: optimization level '-O{{.*}}' is not supported; using '-O3' instead
More information about the cfe-commits
mailing list