analyzer: handle error/error_at_line [PR99196]
authorDavid Malcolm <dmalcolm@redhat.com>
Mon, 22 Feb 2021 23:46:05 +0000 (18:46 -0500)
committerDavid Malcolm <dmalcolm@redhat.com>
Mon, 22 Feb 2021 23:46:05 +0000 (18:46 -0500)
commit5ee4ba031dd9fc60bf2494ca30f46c0acaa34805
treea8f78d8b5ba74d0c16c5f5655244220ac862dd89
parent609204abb889166c17a600121ba8ced18db2567a
analyzer: handle error/error_at_line [PR99196]

PR analyzer/99196 describes a false positive from -fanalyzer due to
the analyzer not "knowing" that calls to GNU libc's error(3) with a
nonzero status terminate the process and thus don't return.

This patch fixes the false positive by special-casing "error" and
"error_at_line".

gcc/analyzer/ChangeLog:
PR analyzer/99196
* engine.cc (exploded_node::on_stmt): Provide terminate_path
flag as a way for on_call_pre to terminate the current analysis
path.
* region-model-impl-calls.cc (call_details::num_args): New.
(region_model::impl_call_error): New.
* region-model.cc (region_model::on_call_pre): Add param
"out_terminate_path".  Handle "error" and "error_at_line".
* region-model.h (call_details::num_args): New decl.
(region_model::on_call_pre): Add param "out_terminate_path".
(region_model::impl_call_error): New decl.

gcc/testsuite/ChangeLog:
PR analyzer/99196
* gcc.dg/analyzer/error-1.c: New test.
* gcc.dg/analyzer/error-2.c: New test.
* gcc.dg/analyzer/error-3.c: New test.
gcc/analyzer/engine.cc
gcc/analyzer/region-model-impl-calls.cc
gcc/analyzer/region-model.cc
gcc/analyzer/region-model.h
gcc/testsuite/gcc.dg/analyzer/error-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/analyzer/error-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/analyzer/error-3.c [new file with mode: 0644]