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

Arthur O'Dwyer arthur.j.odwyer at gmail.com
Mon Nov 11 11:54:55 PST 2013


On Mon, Nov 11, 2013 at 11:35 AM, Chandler Carruth <chandlerc at google.com> wrote:
>
> On Mon, Nov 11, 2013 at 11:01 AM, Sylvestre Ledru <sylvestre at debian.org> wrote:
>>
>> 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'
>
> Sorry that I missed the original thread here, but why is this the desired
> behavior?
>
> My preference would be to have '-O' be the fallback, and that in turn be
> equivalent to '-O2' which is often viewed as a reasonable default level of
> optimization.

Note that the commit message is no longer 100% non-misleading. The
message actually given by the code is "optimization level '-O20' is
unsupported; using '-O3' instead."

The English semantics aren't "oh no, we don't know the user's intent,
let's do something sensible instead." The English semantics are more
like "aha, the user explicitly requested CRAZY HIGH levels of
optimization; let's give him the highest level we currently support."

Existing projects use things like -O99 for this purpose.

You would probably agree that it doesn't make sense to have -O4
perform fewer optimizations than -O3, right?  That's what would happen
if you made -O4 (-O5, -O99) equivalent to -O2.  (Also what Hal said.
:))

–Arthur




More information about the cfe-commits mailing list