This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by sylvestre.ledru on Nov 12 2013, 10:15 AM.

Details

Summary

Currently with clang:
$ clang -O20 foo.c
error: invalid value '20' in '-O20'

With the patch:
$ clang -O20 foo.c
warning: optimization level '-O20' is unsupported; using '-O3' instead.
1 warning generated.

This matches the gcc behavior (with a warning added)

Pass all tests:
Testing: 0 .. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
Testing Time: 94.14s

Expected Passes    : 6721
Expected Failures  : 20
Unsupported Tests  : 17

(which was not the case of http://llvm-reviews.chandlerc.com/D2125)

Diff Detail

Event Timeline

I am open to change to -O2 if you think it is more relevant...

rengolin accepted this revision.Nov 13 2013, 1:18 AM

I think -O3 is the correct level. LGTM.

sylvestre.ledru updated this revision to Unknown Object (????).Nov 14 2013, 5:18 AM

Document the change in the release

Sylvestre, you got a profile-sample-use change together with your doc change. ;)

Oh, or maybe you didn't re-base, and phabricator got crazy... I think...

Chandler, Rafael, is that OK with you?

I just committed to make sure it will be in the 3.4 branch.
However, if there is a consensus to revert this change, I won't mind doing it :)
(as you can imagine, this commit goal is to simplify the transition from gcc to clang)

ygao added a subscriber: ygao.Oct 2 2014, 5:44 PM

There is a problem in this implementation. At Line#302 of lib/Frontend/CompilerInvocation.cpp:
Opts.OptimizationLevel = getOptimizationLevel(Args, IK, Diags);

Notice that Opts.OptimizationLevel is a 3-bit bitfield, so any optimization bigger than 8 are truncated, so
for example, in test/Driver/invalid-o-level.c, you have checked that you get a nice diagnostic for -O900, but
if you try -O899, you will not get any diagnostics.

I think one needs to diagnose on the unsigned optimization level before assigning it to the bitfield.