This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Patch: New implementation of -Wstrict-aliasing


Gabriel Dos Reis wrote:
| Let me know what you think of this:
| Keep the current check in the front-end, but give it two flavors:
| 1. Only warn when the converted pointer is dereferenced immediately:
| *(int*)&float_var.
| 2. The original, which warns even if it is not dereferenced:
| (int*)&float_var.
| One of the two versions would be selected based on the value of
| --param wstrict-aliasing-accuracy.  I would go for version 1 included
| by default, because 2 gives false positives.

The aliasing warning is less of the compiler internals tinkering than
general statements about user codes, so the use of --param is
inappropriate. If necessary, please consider extending -Wstrict-aliasing to take an argument, e.g.


-Wstrict-aliasing=level
Can you please advise on the following choice of warning levels. Please let me know which of the following levels you would like to see in 4.3, in which order. In all cases, the warnings are conditioned by -fstrict-aliasing.
Thank you,
Silvius


-Wstrict-aliasing=1 (default)
===================
Should have very few false positives and few false negatives.
Takes care of the common punn+dereference pattern in the front end: *(int*)&some_float.
Takes care of multiple statement cases in the back end, using flow-sensitive points-to information (-O required).
Uses alias_sets_conflict_p to compare types and only warns when the converted pointer is dereferenced.
Does not warn about incomplete type punning.


-Wstrict-aliasing=2
===================
Variation on level 1, but uses techniques that increase overall accuracy, at the cost of slightly more false positives.
This is actually the most accurate overall, but my current implementation has some false positives during bootstrap, so it cannot be the default.
Runs in the front end and back end. In addition to level 1, it reports aliases to heap variables and structure fields.


-Wstrict-aliasing=3
===================
More aggressive, less precise. Similar to the current -Wstrict-aliasing=2.
May have many false positives but few false negatives.
Runs only in the front end. Uses alias_sets_might_conflict to compare types. Does not check for pointer dereferences. Only warns when an address is taken. Warns about incomplete type punning.


-Wstrict-aliasing=4
===================
Most aggressive, least precise. Possibly useful when levels 1-3 do not warn, but -fstrict-aliasing still breaks the code.
Variation on level 3, but warns even when no address is taken.


Even at level 4, there are situations where the code may not follow the language standard, but no warnings are issued. For instance, we do not warn about possible type punning involving escaping pointers.




-- Silvius Rus Google Inc. rus@google.com (650) 253-0159


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]