forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[analyzer] Fix StackAddrEscapeChecker crash on temporary object fields (
llvm#66493) Basically, the issue was that we should have unwrapped the base region before we special handle temp object regions. Fixes llvm#66221 I also decided to add some extra range information to the diagnostics to make it consistent with the other reporting path.
- Loading branch information
Showing
2 changed files
with
36 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// 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()(); | ||
} |