diff options
author | David Malcolm <dmalcolm@redhat.com> | 2024-05-09 13:09:29 -0400 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2024-05-09 13:09:29 -0400 |
commit | 994477c41049d45b60a4d6db7f624fe5c89860fe (patch) | |
tree | 7cc2dff408c0ebd6ca494fa947c3630b5cb61419 /gcc/analyzer/sm-malloc.cc | |
parent | a1cb188cb2ca2ad3f4e837dba2967f323669d36e (diff) | |
download | gcc-994477c41049d45b60a4d6db7f624fe5c89860fe.zip gcc-994477c41049d45b60a4d6db7f624fe5c89860fe.tar.gz gcc-994477c41049d45b60a4d6db7f624fe5c89860fe.tar.bz2 |
analyzer: fix deref-before-check false positives due to inlining [PR112790]
Backported from commit r14-6918-g5743e1899d5964 (moving testcase from
c-c++-common to gcc.dg).
gcc/analyzer/ChangeLog:
PR analyzer/112790
* checker-event.cc (class inlining_info): Move to...
* inlining-iterator.h (class inlining_info): ...here.
* sm-malloc.cc: Include "analyzer/inlining-iterator.h".
(maybe_complain_about_deref_before_check): Reject stmts that were
inlined from another function.
gcc/testsuite/ChangeLog:
PR analyzer/112790
* gcc.dg/analyzer/deref-before-check-pr112790.c: New test.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diffstat (limited to 'gcc/analyzer/sm-malloc.cc')
-rw-r--r-- | gcc/analyzer/sm-malloc.cc | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/gcc/analyzer/sm-malloc.cc b/gcc/analyzer/sm-malloc.cc index 7470137..64295cf 100644 --- a/gcc/analyzer/sm-malloc.cc +++ b/gcc/analyzer/sm-malloc.cc @@ -47,6 +47,7 @@ along with GCC; see the file COPYING3. If not see #include "analyzer/program-state.h" #include "analyzer/checker-event.h" #include "analyzer/exploded-graph.h" +#include "analyzer/inlining-iterator.h" #if ENABLE_ANALYZER @@ -2147,6 +2148,15 @@ maybe_complain_about_deref_before_check (sm_context *sm_ctxt, if (checked_in_frame->get_index () > assumed_nonnull_in_frame->get_index ()) return; + /* Don't complain if STMT was inlined from another function, to avoid + similar false positives involving shared helper functions. */ + if (stmt->location) + { + inlining_info info (stmt->location); + if (info.get_extra_frames () > 0) + return; + } + tree diag_ptr = sm_ctxt->get_diagnostic_tree (ptr); if (diag_ptr) sm_ctxt->warn |