r194403 - Using an invalid -O falls back on -O3 instead of an error

Rafael EspĂ­ndola rafael.espindola at gmail.com
Mon Nov 11 11:44:38 PST 2013


This broke Driver/clang_f_opts.c on darwin at least.



On 11 November 2013 14:01, Sylvestre Ledru <sylvestre at debian.org> wrote:
> Author: sylvestre
> Date: Mon Nov 11 13:01:05 2013
> New Revision: 194403
>
> URL: http://llvm.org/viewvc/llvm-project?rev=194403&view=rev
> Log:
> Using an invalid -O falls back on -O3 instead of an error
>
> Summary:
> 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'
>
> Reviewers: rengolin, hfinkel
>
> Reviewed By: rengolin
>
> CC: cfe-commits, hfinkel, rengolin
>
> Differential Revision: http://llvm-reviews.chandlerc.com/D2125
>
> Modified:
>     cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
>     cfe/trunk/lib/Driver/Tools.cpp
>     cfe/trunk/lib/Frontend/CompilerInvocation.cpp
>     cfe/trunk/test/Driver/clang_f_opts.c
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=194403&r1=194402&r2=194403&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Mon Nov 11 13:01:05 2013
> @@ -113,6 +113,7 @@ def err_drv_unknown_toolchain : Error<
>    "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<"optimization level '%0' is unsupported; using '%1%2' instead.">;
>  def warn_c_kext : Warning<
>    "ignoring -fapple-kext which is valid for C++ and Objective-C++ only">;
>  def warn_drv_input_file_unused : Warning<
>
> Modified: cfe/trunk/lib/Driver/Tools.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=194403&r1=194402&r2=194403&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Driver/Tools.cpp (original)
> +++ cfe/trunk/lib/Driver/Tools.cpp Mon Nov 11 13:01:05 2013
> @@ -2727,7 +2727,7 @@ void Clang::ConstructJob(Compilation &C,
>    // preprocessed inputs and configure concludes that -fPIC is not supported.
>    Args.ClaimAllArgs(options::OPT_D);
>
> -  // Manually translate -O4 to -O3; let clang reject others.
> +  // Manually translate -O4 to -O3; let clang fall back on -O3 for others
>    if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
>      if (A->getOption().matches(options::OPT_O4)) {
>        CmdArgs.push_back("-O3");
>
> Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=194403&r1=194402&r2=194403&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
> +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Mon Nov 11 13:01:05 2013
> @@ -299,14 +299,14 @@ static bool ParseCodeGenArgs(CodeGenOpti
>    using namespace options;
>    bool Success = true;
>
> -  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;
> +  Opts.OptimizationLevel = getOptimizationLevel(Args, IK, Diags);
> +  unsigned MaxOptLevel = 3;
> +  if (Opts.OptimizationLevel > MaxOptLevel) {
> +    // If the optimization level is not supported, fall back on the default optimization
> +    Diags.Report(diag::warn_drv_invalid_value)
> +        << Args.getLastArg(OPT_O)->getAsString(Args) << "-O" << MaxOptLevel;
> +    Opts.OptimizationLevel = MaxOptLevel;
>    }
> -  Opts.OptimizationLevel = OptLevel;
>
>    // We must always run at least the always inlining pass.
>    Opts.setInlining(
>
> Modified: cfe/trunk/test/Driver/clang_f_opts.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/clang_f_opts.c?rev=194403&r1=194402&r2=194403&view=diff
> ==============================================================================
> --- cfe/trunk/test/Driver/clang_f_opts.c (original)
> +++ cfe/trunk/test/Driver/clang_f_opts.c Mon Nov 11 13:01:05 2013
> @@ -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: optimization level '-O20' is unsupported; using '-O3' instead.
> +
>  // Test that we don't error on these.
>  // RUN: %clang -### -S -Werror                                                \
>  // RUN:     -falign-functions -falign-functions=2 -fno-align-functions        \
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits



More information about the cfe-commits mailing list