Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CFG] [analyzer] Add stubs for constructor and message argument const…
…ructors. CFG now correctly identifies construction context for temporaries constructed for the purpose of passing into a function as an argument. Such context is still not fully implemented because the information it provides is not rich enough: it doens't contain information about argument index. It will be addresssed later. This patch is an extension of r330377 to C++ construct-expressions and Objective-C message expressions which aren't call-expressions but require similar handling. C++ new-expressions with placement arguments still remain to be handled. Differential Revision: https://reviews.llvm.org/D49826 llvm-svn: 338425
- Loading branch information
Showing
6 changed files
with
173 additions
and
12 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
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,41 @@ | ||
// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -triple x86_64-apple-darwin12 -std=c++11 -w %s > %t 2>&1 | ||
// RUN: FileCheck --input-file=%t -check-prefixes=CHECK,CXX11,ELIDE,CXX11-ELIDE %s | ||
// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -triple x86_64-apple-darwin12 -std=c++17 -w %s > %t 2>&1 | ||
// RUN: FileCheck --input-file=%t -check-prefixes=CHECK,CXX17,ELIDE,CXX17-ELIDE %s | ||
// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -triple x86_64-apple-darwin12 -std=c++11 -w -analyzer-config elide-constructors=false %s > %t 2>&1 | ||
// RUN: FileCheck --input-file=%t -check-prefixes=CHECK,CXX11,NOELIDE,CXX11-NOELIDE %s | ||
// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -triple x86_64-apple-darwin12 -std=c++17 -w -analyzer-config elide-constructors=false %s > %t 2>&1 | ||
// RUN: FileCheck --input-file=%t -check-prefixes=CHECK,CXX17,NOELIDE,CXX17-NOELIDE %s | ||
|
||
class D { | ||
public: | ||
D(); | ||
~D(); | ||
}; | ||
|
||
@interface E {} | ||
-(void) foo: (D) d; | ||
@end | ||
|
||
// FIXME: Find construction context for the argument. | ||
// CHECK: void passArgumentIntoMessage(E *e) | ||
// CHECK: 1: e | ||
// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, LValueToRValue, E *) | ||
// CXX11-NEXT: 3: D() (CXXConstructExpr, [B1.4], [B1.6], class D) | ||
// CXX11-NEXT: 4: [B1.3] (BindTemporary) | ||
// CXX11-NEXT: 5: [B1.4] (ImplicitCastExpr, NoOp, const class D) | ||
// CXX11-NEXT: 6: [B1.5] | ||
// CXX11-NEXT: 7: [B1.6] (CXXConstructExpr, class D) | ||
// CXX11-NEXT: 8: [B1.7] (BindTemporary) | ||
// Double brackets trigger FileCheck variables, escape. | ||
// CXX11-NEXT: 9: {{\[}}[B1.2] foo:[B1.8]] | ||
// CXX11-NEXT: 10: ~D() (Temporary object destructor) | ||
// CXX11-NEXT: 11: ~D() (Temporary object destructor) | ||
// CXX17-NEXT: 3: D() (CXXConstructExpr, class D) | ||
// CXX17-NEXT: 4: [B1.3] (BindTemporary) | ||
// Double brackets trigger FileCheck variables, escape. | ||
// CXX17-NEXT: 5: {{\[}}[B1.2] foo:[B1.4]] | ||
// CXX17-NEXT: 6: ~D() (Temporary object destructor) | ||
void passArgumentIntoMessage(E *e) { | ||
[e foo: D()]; | ||
} |
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,23 @@ | ||
// RUN: %clang_analyze_cc1 -analyzer-checker core,cplusplus -verify %s | ||
|
||
// expected-no-diagnostics | ||
|
||
// Stripped down unique_ptr<int> | ||
struct IntPtr { | ||
IntPtr(): i(new int) {} | ||
IntPtr(IntPtr &&o): i(o.i) { o.i = nullptr; } | ||
~IntPtr() { delete i; } | ||
|
||
int *i; | ||
}; | ||
|
||
@interface Foo {} | ||
-(void) foo: (IntPtr)arg; | ||
@end | ||
|
||
void bar(Foo *f) { | ||
IntPtr ptr; | ||
int *i = ptr.i; | ||
[f foo: static_cast<IntPtr &&>(ptr)]; | ||
*i = 99; // no-warning | ||
} |