Skip to content
Snippets Groups Projects
user avatar
David Malcolm authored
Integration testing showed various false positives from
-Wanalyzer-deref-before-check where the expression that's dereferenced
is different from the one that's checked, but the diagnostic is emitted
because they both evaluate to the same symbolic value.

This patch rejects such warnings, unless we have tree expressions for
both and that both tree expressions are "spelled the same way" i.e.
would be printed to the same user-facing string.

gcc/analyzer/ChangeLog:
	PR analyzer/108475
	PR analyzer/109060
	* sm-malloc.cc (deref_before_check::deref_before_check):
	Initialize new field m_deref_expr.  Assert that arg is non-NULL.
	(deref_before_check::emit): Reject cases where the spelling of the
	thing that was dereferenced differs from that of what is checked,
	or if the dereference expression was not found.  Remove code to
	handle NULL m_arg.
	(deref_before_check::describe_state_change): Remove code to handle
	NULL m_arg.
	(deref_before_check::describe_final_event): Likewise.
	(deref_before_check::sufficiently_similar_p): New.
	(deref_before_check::m_deref_expr): New field.
	(malloc_state_machine::maybe_complain_about_deref_before_check):
	Don't warn if the diag_ptr is NULL.

gcc/testsuite/ChangeLog:
	PR analyzer/108475
	PR analyzer/109060
	* gcc.dg/analyzer/deref-before-check-pr108475-1.c: New test.
	* gcc.dg/analyzer/deref-before-check-pr108475-haproxy-tcpcheck.c:
	New test.
	* gcc.dg/analyzer/deref-before-check-pr109060-haproxy-cfgparse.c:
	New test.

Signed-off-by: default avatarDavid Malcolm <dmalcolm@redhat.com>
c4fd232f
History
Name Last commit Last update