aboutsummaryrefslogtreecommitdiff
path: root/gcc/analyzer/sm-malloc.cc
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2024-01-04 09:15:18 -0500
committerDavid Malcolm <dmalcolm@redhat.com>2024-01-04 09:15:18 -0500
commit5743e1899d596497800f7d6f4273d535ea0abcdd (patch)
tree89e1b499f39b36abef5eecc24455c1ddcdb4ca3a /gcc/analyzer/sm-malloc.cc
parentdb5b01d282a0e3ddcac737e55f9758c8b081cf4b (diff)
downloadgcc-5743e1899d596497800f7d6f4273d535ea0abcdd.zip
gcc-5743e1899d596497800f7d6f4273d535ea0abcdd.tar.gz
gcc-5743e1899d596497800f7d6f4273d535ea0abcdd.tar.bz2
analyzer: fix deref-before-check false positives due to inlining [PR112790]
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 * c-c++-common/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.cc10
1 files changed, 10 insertions, 0 deletions
diff --git a/gcc/analyzer/sm-malloc.cc b/gcc/analyzer/sm-malloc.cc
index 8da2e7c..2e0cf8a 100644
--- a/gcc/analyzer/sm-malloc.cc
+++ b/gcc/analyzer/sm-malloc.cc
@@ -46,6 +46,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
@@ -2168,6 +2169,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