This flag was introduced by6818991d71commit6818991d71Author: Ted Kremenek <kremenek@apple.com> Date: Mon Dec 7 22:06:12 2009 +0000 Add clang-cc option '-analyzer-opt-analyze-nested-blocks' to treat block literals as an entry point for analyzer checks. The last reference was removed by this commit:5c32dfc5fbcommit5c32dfc5fbAuthor: Anna Zaks <ganna@apple.com> Date: Fri Dec 21 01:19:15 2012 +0000 [analyzer] Add blocks and ObjC messages to the call graph. This paves the road for constructing a better function dependency graph. If we analyze a function before the functions it calls and inlines, there is more opportunity for optimization. Note, we add call edges to the called methods that correspond to function definitions (declarations with bodies). Consequently, we should remove this dead flag. However, this arises a couple of burning questions. - Should the `cc1` frontend still accept this flag - to keep tools/users passing this flag directly to `cc1` (which is unsupported, unadvertised) working. - If we should remain backward compatible, how long? - How can we get rid of deprecated and obsolete flags at some point? Reviewed By: martong Differential Revision: https://reviews.llvm.org/D126067
89 lines
3.3 KiB
Plaintext
89 lines
3.3 KiB
Plaintext
// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core -fblocks -verify -x objective-c++ %s
|
|
// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,debug.DumpCFG -fblocks -analyzer-config cfg-rich-constructors=false %s > %t 2>&1
|
|
// RUN: FileCheck --input-file=%t -check-prefixes=CHECK,WARNINGS %s
|
|
// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,debug.DumpCFG -fblocks -analyzer-config cfg-rich-constructors=true %s > %t 2>&1
|
|
// RUN: FileCheck --input-file=%t -check-prefixes=CHECK,ANALYZER %s
|
|
|
|
// This file tests how we construct two different flavors of the Clang CFG -
|
|
// the CFG used by the Sema analysis-based warnings and the CFG used by the
|
|
// static analyzer. The difference in the behavior is checked via FileCheck
|
|
// prefixes (WARNINGS and ANALYZER respectively). When introducing new analyzer
|
|
// flags, no new run lines should be added - just these flags would go to the
|
|
// respective line depending on where is it turned on and where is it turned
|
|
// off. Feel free to add tests that test only one of the CFG flavors if you're
|
|
// not sure how the other flavor is supposed to work in your case.
|
|
|
|
// expected-no-diagnostics
|
|
|
|
void testBlockWithoutCopyExpression(int i) {
|
|
// Captures i, with no copy expression.
|
|
(void)(^void() {
|
|
(void)i;
|
|
});
|
|
}
|
|
|
|
// CHECK-LABEL:void testBlockWithoutCopyExpression(int i)
|
|
// CHECK-NEXT: [B2 (ENTRY)]
|
|
// CHECK-NEXT: Succs (1): B1
|
|
|
|
// CHECK: [B1]
|
|
// CHECK-NEXT: 1: ^{ }
|
|
// CHECK-NEXT: 2: (void)([B1.1]) (CStyleCastExpr, ToVoid, void)
|
|
// CHECK-NEXT: Preds (1): B2
|
|
// CHECK-NEXT: Succs (1): B0
|
|
|
|
// CHECK: [B0 (EXIT)]
|
|
// CHECK-NEXT: Preds (1): B1
|
|
|
|
struct StructWithCopyConstructor {
|
|
StructWithCopyConstructor(int i);
|
|
StructWithCopyConstructor(const StructWithCopyConstructor &s);
|
|
};
|
|
void testBlockWithCopyExpression(StructWithCopyConstructor s) {
|
|
// Captures s, with a copy expression calling the copy constructor for StructWithCopyConstructor.
|
|
(void)(^void() {
|
|
(void)s;
|
|
});
|
|
}
|
|
|
|
// CHECK-LABEL:void testBlockWithCopyExpression(StructWithCopyConstructor s)
|
|
// CHECK-NEXT: [B2 (ENTRY)]
|
|
// CHECK-NEXT: Succs (1): B1
|
|
|
|
// CHECK: [B1]
|
|
// CHECK-NEXT: 1: s
|
|
// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, NoOp, const struct StructWithCopyConstructor)
|
|
// CHECK-NEXT: 3: [B1.2] (CXXConstructExpr, const struct StructWithCopyConstructor)
|
|
// CHECK-NEXT: 4: ^{ }
|
|
// CHECK-NEXT: 5: (void)([B1.4]) (CStyleCastExpr, ToVoid, void)
|
|
// CHECK-NEXT: Preds (1): B2
|
|
// CHECK-NEXT: Succs (1): B0
|
|
|
|
// CHECK: [B0 (EXIT)]
|
|
// CHECK-NEXT: Preds (1): B1
|
|
|
|
void testBlockWithCaptureByReference() {
|
|
__block StructWithCopyConstructor s(5);
|
|
// Captures s by reference, so no copy expression.
|
|
(void)(^void() {
|
|
(void)s;
|
|
});
|
|
}
|
|
|
|
// CHECK-LABEL:void testBlockWithCaptureByReference()
|
|
// CHECK-NEXT: [B2 (ENTRY)]
|
|
// CHECK-NEXT: Succs (1): B1
|
|
|
|
// CHECK: [B1]
|
|
// CHECK-NEXT: 1: 5
|
|
// WARNINGS-NEXT: 2: [B1.1] (CXXConstructExpr, struct StructWithCopyConstructor)
|
|
// ANALYZER-NEXT: 2: [B1.1] (CXXConstructExpr, [B1.3], struct StructWithCopyConstructor)
|
|
// CHECK-NEXT: 3: StructWithCopyConstructor s(5) __attribute__((blocks("byref")));
|
|
// CHECK-NEXT: 4: ^{ }
|
|
// CHECK-NEXT: 5: (void)([B1.4]) (CStyleCastExpr, ToVoid, void)
|
|
// CHECK-NEXT: Preds (1): B2
|
|
// CHECK-NEXT: Succs (1): B0
|
|
|
|
// CHECK: [B0 (EXIT)]
|
|
// CHECK-NEXT: Preds (1): B1
|