aboutsummaryrefslogtreecommitdiff
path: root/gcc/analyzer/inlining-iterator.h
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/inlining-iterator.h
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/inlining-iterator.h')
-rw-r--r--gcc/analyzer/inlining-iterator.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/gcc/analyzer/inlining-iterator.h b/gcc/analyzer/inlining-iterator.h
index d6314d0..e65caa4 100644
--- a/gcc/analyzer/inlining-iterator.h
+++ b/gcc/analyzer/inlining-iterator.h
@@ -106,4 +106,44 @@ private:
tree m_next_abstract_origin;
};
+/* A class for fixing up fndecls and stack depths in checker_event, based
+ on inlining records.
+
+ The early inliner runs before the analyzer, which can lead to confusing
+ output.
+
+ Tne base fndecl and depth within a checker_event are from call strings
+ in program_points, which reflect the call strings after inlining.
+ This class lets us offset the depth and fix up the reported fndecl and
+ stack depth to better reflect the user's original code. */
+
+class inlining_info
+{
+public:
+ inlining_info (location_t loc)
+ {
+ inlining_iterator iter (loc);
+ m_inner_fndecl = iter.get_fndecl ();
+ int num_frames = 0;
+ while (!iter.done_p ())
+ {
+ m_outer_fndecl = iter.get_fndecl ();
+ num_frames++;
+ iter.next ();
+ }
+ if (num_frames > 1)
+ m_extra_frames = num_frames - 1;
+ else
+ m_extra_frames = 0;
+ }
+
+ tree get_inner_fndecl () const { return m_inner_fndecl; }
+ int get_extra_frames () const { return m_extra_frames; }
+
+private:
+ tree m_outer_fndecl;
+ tree m_inner_fndecl;
+ int m_extra_frames;
+};
+
#endif /* GCC_ANALYZER_INLINING_ITERATOR_H */