-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[analyzer] Bind return value for assigment and copies of trivial empt…
…y classes We now properly bind return value of the trivial copy constructor and assignments of the empty objects. Such operations do not perform any loads from the source, however they preserve identity of the assigned object: ``` Empty e; auto& x = (e = Empty()); clang_analyzer_dump(x); // &e, was Unknown ``` Reviewed By: xazax.hun Differential Revision: https://reviews.llvm.org/D155442
- Loading branch information
Tomasz Kamiński
committed
Jul 18, 2023
1 parent
ef7d537
commit 61760bb
Showing
2 changed files
with
52 additions
and
18 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,34 @@ | ||
// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config c++-inlining=constructors -verify %s | ||
|
||
|
||
template<typename T> | ||
void clang_analyzer_dump(T&); | ||
|
||
struct aggr { | ||
int x; | ||
int y; | ||
}; | ||
|
||
struct empty { | ||
}; | ||
|
||
void test_copy_return() { | ||
aggr s1 = {1, 2}; | ||
aggr const& cr1 = aggr(s1); | ||
clang_analyzer_dump(cr1); // expected-warning-re {{&lifetime_extended_object{aggr, cr1, S{{[0-9]+}}} }} | ||
|
||
empty s2; | ||
empty const& cr2 = empty{s2}; | ||
clang_analyzer_dump(cr2); // expected-warning-re {{&lifetime_extended_object{empty, cr2, S{{[0-9]+}}} }} | ||
} | ||
|
||
void test_assign_return() { | ||
aggr s1 = {1, 2}; | ||
aggr d1; | ||
clang_analyzer_dump(d1 = s1); // expected-warning {{&d1 }} | ||
|
||
empty s2; | ||
empty d2; | ||
clang_analyzer_dump(d2 = s2); // expected-warning {{&d2 }} was Unknown | ||
} | ||
|