Bug 91406 - gcc -Q -v lies about what flags are enabled
Summary: gcc -Q -v lies about what flags are enabled
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: driver (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-08-08 21:25 UTC by Steve Ellcey
Modified: 2022-11-28 03:15 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-01-27 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Steve Ellcey 2019-08-08 21:25:29 UTC
If you run 'gcc -Q -v x.c'  and look at the 'options enabled:' list, it is not accurate.  For example, on aarch64 it will show '-fprefetch-loop-arrays' which is not on by default for a generic aarch64 compiles (even at -O3).  The problem is that this flag is initialized to -1 and it might be overridden by aarch64_override_options_internal in some cases to turn it on but if it is not
overridden it stays at -1 and then option_enabled (opts-common.c) checks
to see if it is zero or not-zero and if not-zero it returns true and says it
is enabled.  Note that in this case the compiler will not actually generate
prefetch instructions because the gate function is checking for 'x > 0', not
'x != 0' like option_enabled does.

This can affect any option in commons.opt (or elsewhere) that is initialized to -1.  There are also flags that are initialized to 1 but probably should not show up if compiling at -O0 because in that case the pass that would check the flag is never called, such as -faggressive-loop-optimizations for example.  If you run a '-Q -v -O0' compilation on x86 the list of enabled options will include -faggressive-loop-optimizations which I am sure is not actually run.  I guess you could claim it is enabled but not run, but that seems unhelpful.

I could fix the specific aarch64 '-fprefetch-loop-arrays' bug by having aarch64_override_options_internal set the prefetch flag to 0 in those cases where it is not setting it to 1.  That way it would never be -1 when option_enabled checks it, but I am not sure this the right/best fix.
Comment 1 Richard Biener 2019-08-09 07:49:11 UTC
-Q -v is only a wild guess given whether options are enabled or disabled may depend on the function context.  There's really no way to implement it accurately
(this -1 trick for "auto-detection" could eventually be handled in some
generic way, saying not enabled/disabled but "<auto>" or "<unknown>")