llvm-project/clang/test/Analysis/stackaddrleak.cpp
Balazs Benics 73dcbd411b
[analyzer] Fix StackAddrEscapeChecker crash on temporary object fields (#66493)
Basically, the issue was that we should have unwrapped the
base region before we special handle temp object regions.

Fixes https://github.com/llvm/llvm-project/issues/66221

I also decided to add some extra range information to the diagnostics
to make it consistent with the other reporting path.
2023-09-20 13:54:21 +02:00

26 lines
676 B
C++

// RUN: %clang_analyze_cc1 -analyzer-checker=core -verify %s
using size_t = decltype(sizeof(int));
void *operator new(size_t, void *p) { return p; }
struct myfunction {
union storage_t {
char buffer[100];
size_t max_align;
} storage;
template <typename Func> myfunction(Func fn) {
new (&storage.buffer) Func(fn);
}
void operator()();
};
myfunction create_func() {
int n;
auto c = [&n] {};
return c; // expected-warning {{Address of stack memory associated with local variable 'n' is still referred to by a temporary object on the stack upon returning to the caller. This will be a dangling reference}}
}
void gh_66221() {
create_func()();
}