[PATCH] Using an invalid -O falls back on -O3 instead of an error
Sylvestre Ledru
sylvestre at debian.org
Fri Nov 8 06:05:09 PST 2013
sylvestre.ledru added you to the CC list for the revision "Using an invalid -O falls back on -O3 instead of an error".
Currently with clang:
$ clang -O20 foo.c
error: invalid value '20' in '-O20'
With the patch:
$ clang -O20 foo.c
warning: invalid value '20' in '-O20'. Fall back on value '3'
http://llvm-reviews.chandlerc.com/D2125
Files:
include/clang/Basic/DiagnosticDriverKinds.td
lib/Frontend/CompilerInvocation.cpp
test/Driver/clang_f_opts.c
Index: include/clang/Basic/DiagnosticDriverKinds.td
===================================================================
--- include/clang/Basic/DiagnosticDriverKinds.td
+++ include/clang/Basic/DiagnosticDriverKinds.td
@@ -113,6 +113,7 @@
"cannot recognize the type of the toolchain">;
def warn_O4_is_O3 : Warning<"-O4 is equivalent to -O3">, InGroup<Deprecated>;
+def warn_drv_invalid_value : Warning<"invalid value '%1' in '%0'. Fall back on value '%2'">;
def warn_c_kext : Warning<
"ignoring -fapple-kext which is valid for C++ and Objective-C++ only">;
def warn_drv_input_file_unused : Warning<
Index: lib/Frontend/CompilerInvocation.cpp
===================================================================
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -301,10 +301,10 @@
unsigned OptLevel = getOptimizationLevel(Args, IK, Diags);
if (OptLevel > 3) {
- Diags.Report(diag::err_drv_invalid_value)
- << Args.getLastArg(OPT_O)->getAsString(Args) << OptLevel;
- OptLevel = 3;
- Success = false;
+ unsigned DefaultOptLevel = 3;
+ Diags.Report(diag::warn_drv_invalid_value)
+ << Args.getLastArg(OPT_O)->getAsString(Args) << OptLevel << DefaultOptLevel;
+ OptLevel = DefaultOptLevel;
}
Opts.OptimizationLevel = OptLevel;
Index: test/Driver/clang_f_opts.c
===================================================================
--- test/Driver/clang_f_opts.c
+++ test/Driver/clang_f_opts.c
@@ -100,6 +100,9 @@
// CHECK-MAX-O: warning: -O4 is equivalent to -O3
// CHECK-MAX-O: -O3
+// RUN: %clang -### -S -O20 %s 2>&1 | FileCheck -check-prefix=CHECK-INVALID-O %s
+// CHECK-INVALID-O: warning: invalid value '20' in '-O20'. Fall back on value '3'
+
// Test that we don't error on these.
// RUN: %clang -### -S -Werror \
// RUN: -falign-functions -falign-functions=2 -fno-align-functions \
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2125.1.patch
Type: text/x-patch
Size: 1935 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131108/3ad719b6/attachment.bin>
More information about the cfe-commits
mailing list