analyzer: fix global-sm-state issue affecting sm-signal
authorDavid Malcolm <dmalcolm@redhat.com>
Sat, 21 Dec 2019 13:49:03 +0000 (08:49 -0500)
committerDavid Malcolm <dmalcolm@redhat.com>
Wed, 15 Jan 2020 01:55:47 +0000 (20:55 -0500)
commit7fb3669edb4aa3c8313ddf8b914b86a1623e0954
treeb578fa335525be8fd6e7dc142d11be4e091dc15b
parente2a538b1c31a13fc3d2f6d8ac3f341437775e984
analyzer: fix global-sm-state issue affecting sm-signal

sm-signal.cc was failing to warn about the use of an fprintf call in a
signal handler when the signal handler function was non-static.

The root cause was a failure to copy global sm-state within
sm_state_map::clone_with_remapping as called by
program_state::can_merge_with_p, which led to the exploded node for
the entrypoint to the handler in the "normal" state being erroneously
reused for the "in_signal_handler" state, thus losing the global state,
and thus failing to warn.

This patch fixes the above, so that non-equal global sm-state values
prevent merger of program_state, thus requiring separate exploded nodes
for the "normal" and "in signal handler" states, and thus triggering
the warning for the reproducer.

gcc/analyzer/ChangeLog:
* program-state.cc (sm_state_map::clone_with_remapping): Copy
m_global_state.
(selftest::test_program_state_merging_2): New selftest.
(selftest::analyzer_program_state_cc_tests): Call it.

gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/signal-6.c: New test.
gcc/analyzer/ChangeLog
gcc/analyzer/program-state.cc
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/analyzer/signal-6.c [new file with mode: 0644]