From 5743e1899d596497800f7d6f4273d535ea0abcdd Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Thu, 4 Jan 2024 09:15:18 -0500 Subject: 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 --- gcc/analyzer/sm-malloc.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'gcc/analyzer/sm-malloc.cc') 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 -- cgit v1.1