analyzer: make use of may_be_aliased in alias detection [PR103546]
authorDavid Malcolm <dmalcolm@redhat.com>
Thu, 6 Jan 2022 16:39:54 +0000 (11:39 -0500)
committerDavid Malcolm <dmalcolm@redhat.com>
Thu, 6 Jan 2022 22:42:05 +0000 (17:42 -0500)
commitd564a83d14252d7db01381f71900b7a68357803b
tree70e8a2f5584e04aad396bdd87d181f01f123a8f5
parent8e2771069ed0c157cca825d6af5792e94c4407c1
analyzer: make use of may_be_aliased in alias detection [PR103546]

Whilst debugging PR analyzer/103546 (false +ve in flex-generated lexers)
I noticed that the analyzer was considering that writes through symbolic
pointers could be treated as clobbering static globals such as:

   static YY_BUFFER_STATE * yy_buffer_stack = NULL;

even for such variables that never have their address taken.

This patch fixes this issue at least, so that the analyzer can preserve
knowledge of such globals on code paths with writes through symbolic
pointers.

It does not fix the false +ve in the lexer code.

gcc/analyzer/ChangeLog:
PR analyzer/103546
* store.cc (store::eval_alias_1): Refactor handling of decl
regions, adding a test for may_be_aliased, rejecting those for
which it returns false.

gcc/testsuite/ChangeLog:
PR analyzer/103546
* gcc.dg/analyzer/aliasing-3.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
gcc/analyzer/store.cc
gcc/testsuite/gcc.dg/analyzer/aliasing-3.c [new file with mode: 0644]