[PATCH] Using an invalid -O falls back on -O3 instead of an error

Sylvestre Ledru sylvestre at debian.org
Fri Nov 8 09:43:34 PST 2013


On 08/11/2013 14:53, Sylvestre Ledru wrote:
> 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'

The rational behind this commit is that using a bad value for -O should 
be just a warning. I don't see the value of failing the build. A warning 
should be enough.

In the Debian rebuilds, 49 occurrences of this error have been found [1].
(even if most of them are caused by Pure Data (pd) and fixed upstream [2]).

Thanks
Sylvestre
[1] http://clang.debian.net/status.php?version=3.3&key=WRONG_OPTIM_VAL
[2] http://sourceforge.net/p/pure-data/bugs/1100/
> 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        \
>




More information about the cfe-commits mailing list