forked from llvm-mirror/clang
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[analyzer] Fix invalidation when returning into a ctor initializer.
Due to RVO the target region of a function that returns an object by value isn't necessarily a temporary object region; it may be an arbitrary memory region. In particular, it may be a field of a bigger object. Make sure we don't invalidate the bigger object when said function is evaluated conservatively. Differential Revision: https://reviews.llvm.org/D63968 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@364870 91177308-0d34-0410-b5e6-96231b3b80d8
- Loading branch information
Showing
2 changed files
with
37 additions
and
5 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,cplusplus \ | ||
// RUN: -analyzer-checker debug.ExprInspection -verify %s | ||
|
||
void clang_analyzer_eval(bool); | ||
|
||
struct A { | ||
int x; | ||
}; | ||
|
||
A getA(); | ||
|
||
struct B { | ||
int *p; | ||
A a; | ||
|
||
B(int *p) : p(p), a(getA()) {} | ||
}; | ||
|
||
void foo() { | ||
B b1(nullptr); | ||
clang_analyzer_eval(b1.p == nullptr); // expected-warning{{TRUE}} | ||
B b2(new int); // No leak yet! | ||
clang_analyzer_eval(b2.p == nullptr); // expected-warning{{FALSE}} | ||
// expected-warning@-1{{Potential leak of memory pointed to by 'b2.p'}} | ||
} |