From 3127bf46418960ef98fb2daee3faf4176a08eadb Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Thu, 25 Jun 2020 14:59:07 -0400 Subject: [PATCH 254/315] FIXME: add stale-frame-1.c; tweak wording of POISON_KIND_POPPED_STACK diagnostic --- gcc/analyzer/region-model2.cc | 11 ++++++----- gcc/testsuite/gcc.dg/analyzer/stale-frame-1.c | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/analyzer/stale-frame-1.c diff --git a/gcc/analyzer/region-model2.cc b/gcc/analyzer/region-model2.cc index 1907fbe4c9a..e5f04b5419a 100644 --- a/gcc/analyzer/region-model2.cc +++ b/gcc/analyzer/region-model2.cc @@ -4865,10 +4865,11 @@ public: case POISON_KIND_POPPED_STACK: { /* TODO: which CWE? */ - return warning_at (rich_loc, - OPT_Wanalyzer_use_of_pointer_in_stale_stack_frame, - "use of pointer %qE within stale stack frame", - m_expr); + return warning_at + (rich_loc, + OPT_Wanalyzer_use_of_pointer_in_stale_stack_frame, + "dereferencing pointer %qE to within stale stack frame", + m_expr); } break; } @@ -4888,7 +4889,7 @@ public: m_expr); case POISON_KIND_POPPED_STACK: return ev.formatted_print - ("use of pointer %qE within stale stack frame here", + ("dereferencing pointer %qE to within stale stack frame", m_expr); } } diff --git a/gcc/testsuite/gcc.dg/analyzer/stale-frame-1.c b/gcc/testsuite/gcc.dg/analyzer/stale-frame-1.c new file mode 100644 index 00000000000..04221479bf9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/stale-frame-1.c @@ -0,0 +1,15 @@ + +int *global_ptr; + +static void __attribute__((noinline)) +called_by_test_1 (void) +{ + int i = 42; + global_ptr = &i; +} + +int test_1 (void) +{ + called_by_test_1 (); + return *global_ptr; /* { dg-warning "dereferencing pointer 'global_ptr' to within stale stack frame" } */ +} -- 2.26.2