
#10560: -f and -O options interact in non-obvious, order dependent ways
-------------------------------------+-------------------------------------
Reporter: bgamari | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.10.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Incorrect | Unknown/Multiple
warning at compile-time | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Revisions:
-------------------------------------+-------------------------------------
Comment (by svenpanne):
Hmmm, GCC's behavior is a bit weird, and to be honest: It's the first time
that I've heard of the fact that e.g. -Ofoo is processed before -fblah,
regardless of the order on the command line. Re-reading GCC's
documentation, it is explicitly stated that order is important, but the
docs introduce the notion of "option kind", without actually specifying
what those kinds are and in which order those kinds are processed
(https://gcc.gnu.org/onlinedocs/gcc-5.1.0/gcc/Invoking-GCC.html).
Obviously, the -Ofoo options are of a different kind than the -fblah
options, and the -Ofoo ones are processed before the -fblah ones. *But*
within these kinds, order matters:
{{{
$ gcc -c -Q --help=optimizers -O3 -O0 | grep tree-vectorize
-ftree-vectorize [disabled]
$ gcc -c -Q --help=optimizers -O0 -O3 | grep tree-vectorize
-ftree-vectorize [enabled]
}}}
OTOH, clang doesn't seem to have this notion of "kinds" and simply
processes options in order:
{{{
$ echo 'int x;' | clang -xc -fno-vectorize -O2 - -o /dev/null -\#\#\# 2>&1
| sed 's/\s/\n/g' | grep vectorize-loops
"-vectorize-loops"
$ echo 'int x;' | clang -xc -O2 -fno-vectorize - -o /dev/null -\#\#\# 2>&1
| sed 's/\s/\n/g' | grep vectorize-loops
<no output>
}}}
Same for most other tools, including e.g. git:
{{{
$ git log --pretty=short --oneline
ab3926f Fix PR13851: Preserve metadata for the unswitched branch
9e7539a Remove broken banner.
...
$ git log --oneline --pretty=short
commit ab3926f
Author: Weiming Zhao