analyzer: fix "when 'strchr' returns non-NULL" message
authorDavid Malcolm <dmalcolm@redhat.com>
Tue, 8 Nov 2022 02:52:30 +0000 (21:52 -0500)
committerDavid Malcolm <dmalcolm@redhat.com>
Tue, 8 Nov 2022 02:52:30 +0000 (21:52 -0500)
commit55e042407ef307764cb9d5a4a06954518e2112b4
treefecc03105e1383aaa8137ac98dbcc2d397b2da01
parent8d0326943ee4eb87309faca28ee0ed13346dd70a
analyzer: fix "when 'strchr' returns non-NULL" message

Tweak analyzer handling of strchr, so that we show the
  when 'strchr' returns non-NULL
message for that execution path.

gcc/analyzer/ChangeLog:
* region-model-impl-calls.cc (region_model::impl_call_strchr):
Move to on_call_post.  Handle both outcomes using bifurcation,
rather than just the "not found" case.
* region-model.cc (region_model::on_call_pre): Move
BUILT_IN_STRCHR and "strchr" to...
(region_model::on_call_post): ...here.

gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/strchr-1.c (test_literal): Detect writing to a
string literal.  Verify that we emit the "when '__builtin_strchr'
returns non-NULL" message.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
gcc/analyzer/region-model-impl-calls.cc
gcc/analyzer/region-model.cc
gcc/testsuite/gcc.dg/analyzer/strchr-1.c