annotate clang/test/Analysis/blocks.mm @ 150:1d019706d866

LLVM10
author anatofuz
date Thu, 13 Feb 2020 15:10:13 +0900
parents
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core -fblocks -analyzer-opt-analyze-nested-blocks -verify -x objective-c++ %s
anatofuz
parents:
diff changeset
2 // RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,debug.DumpCFG -fblocks -analyzer-opt-analyze-nested-blocks -analyzer-config cfg-rich-constructors=false %s > %t 2>&1
anatofuz
parents:
diff changeset
3 // RUN: FileCheck --input-file=%t -check-prefixes=CHECK,WARNINGS %s
anatofuz
parents:
diff changeset
4 // RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,debug.DumpCFG -fblocks -analyzer-opt-analyze-nested-blocks -analyzer-config cfg-rich-constructors=true %s > %t 2>&1
anatofuz
parents:
diff changeset
5 // RUN: FileCheck --input-file=%t -check-prefixes=CHECK,ANALYZER %s
anatofuz
parents:
diff changeset
6
anatofuz
parents:
diff changeset
7 // This file tests how we construct two different flavors of the Clang CFG -
anatofuz
parents:
diff changeset
8 // the CFG used by the Sema analysis-based warnings and the CFG used by the
anatofuz
parents:
diff changeset
9 // static analyzer. The difference in the behavior is checked via FileCheck
anatofuz
parents:
diff changeset
10 // prefixes (WARNINGS and ANALYZER respectively). When introducing new analyzer
anatofuz
parents:
diff changeset
11 // flags, no new run lines should be added - just these flags would go to the
anatofuz
parents:
diff changeset
12 // respective line depending on where is it turned on and where is it turned
anatofuz
parents:
diff changeset
13 // off. Feel free to add tests that test only one of the CFG flavors if you're
anatofuz
parents:
diff changeset
14 // not sure how the other flavor is supposed to work in your case.
anatofuz
parents:
diff changeset
15
anatofuz
parents:
diff changeset
16 // expected-no-diagnostics
anatofuz
parents:
diff changeset
17
anatofuz
parents:
diff changeset
18 void testBlockWithoutCopyExpression(int i) {
anatofuz
parents:
diff changeset
19 // Captures i, with no copy expression.
anatofuz
parents:
diff changeset
20 (void)(^void() {
anatofuz
parents:
diff changeset
21 (void)i;
anatofuz
parents:
diff changeset
22 });
anatofuz
parents:
diff changeset
23 }
anatofuz
parents:
diff changeset
24
anatofuz
parents:
diff changeset
25 // CHECK-LABEL:void testBlockWithoutCopyExpression(int i)
anatofuz
parents:
diff changeset
26 // CHECK-NEXT: [B2 (ENTRY)]
anatofuz
parents:
diff changeset
27 // CHECK-NEXT: Succs (1): B1
anatofuz
parents:
diff changeset
28
anatofuz
parents:
diff changeset
29 // CHECK: [B1]
anatofuz
parents:
diff changeset
30 // CHECK-NEXT: 1: ^{ }
anatofuz
parents:
diff changeset
31 // CHECK-NEXT: 2: (void)([B1.1]) (CStyleCastExpr, ToVoid, void)
anatofuz
parents:
diff changeset
32 // CHECK-NEXT: Preds (1): B2
anatofuz
parents:
diff changeset
33 // CHECK-NEXT: Succs (1): B0
anatofuz
parents:
diff changeset
34
anatofuz
parents:
diff changeset
35 // CHECK: [B0 (EXIT)]
anatofuz
parents:
diff changeset
36 // CHECK-NEXT: Preds (1): B1
anatofuz
parents:
diff changeset
37
anatofuz
parents:
diff changeset
38 struct StructWithCopyConstructor {
anatofuz
parents:
diff changeset
39 StructWithCopyConstructor(int i);
anatofuz
parents:
diff changeset
40 StructWithCopyConstructor(const StructWithCopyConstructor &s);
anatofuz
parents:
diff changeset
41 };
anatofuz
parents:
diff changeset
42 void testBlockWithCopyExpression(StructWithCopyConstructor s) {
anatofuz
parents:
diff changeset
43 // Captures s, with a copy expression calling the copy constructor for StructWithCopyConstructor.
anatofuz
parents:
diff changeset
44 (void)(^void() {
anatofuz
parents:
diff changeset
45 (void)s;
anatofuz
parents:
diff changeset
46 });
anatofuz
parents:
diff changeset
47 }
anatofuz
parents:
diff changeset
48
anatofuz
parents:
diff changeset
49 // CHECK-LABEL:void testBlockWithCopyExpression(StructWithCopyConstructor s)
anatofuz
parents:
diff changeset
50 // CHECK-NEXT: [B2 (ENTRY)]
anatofuz
parents:
diff changeset
51 // CHECK-NEXT: Succs (1): B1
anatofuz
parents:
diff changeset
52
anatofuz
parents:
diff changeset
53 // CHECK: [B1]
anatofuz
parents:
diff changeset
54 // CHECK-NEXT: 1: s
anatofuz
parents:
diff changeset
55 // CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, NoOp, const struct StructWithCopyConstructor)
anatofuz
parents:
diff changeset
56 // CHECK-NEXT: 3: [B1.2] (CXXConstructExpr, const struct StructWithCopyConstructor)
anatofuz
parents:
diff changeset
57 // CHECK-NEXT: 4: ^{ }
anatofuz
parents:
diff changeset
58 // CHECK-NEXT: 5: (void)([B1.4]) (CStyleCastExpr, ToVoid, void)
anatofuz
parents:
diff changeset
59 // CHECK-NEXT: Preds (1): B2
anatofuz
parents:
diff changeset
60 // CHECK-NEXT: Succs (1): B0
anatofuz
parents:
diff changeset
61
anatofuz
parents:
diff changeset
62 // CHECK: [B0 (EXIT)]
anatofuz
parents:
diff changeset
63 // CHECK-NEXT: Preds (1): B1
anatofuz
parents:
diff changeset
64
anatofuz
parents:
diff changeset
65 void testBlockWithCaptureByReference() {
anatofuz
parents:
diff changeset
66 __block StructWithCopyConstructor s(5);
anatofuz
parents:
diff changeset
67 // Captures s by reference, so no copy expression.
anatofuz
parents:
diff changeset
68 (void)(^void() {
anatofuz
parents:
diff changeset
69 (void)s;
anatofuz
parents:
diff changeset
70 });
anatofuz
parents:
diff changeset
71 }
anatofuz
parents:
diff changeset
72
anatofuz
parents:
diff changeset
73 // CHECK-LABEL:void testBlockWithCaptureByReference()
anatofuz
parents:
diff changeset
74 // CHECK-NEXT: [B2 (ENTRY)]
anatofuz
parents:
diff changeset
75 // CHECK-NEXT: Succs (1): B1
anatofuz
parents:
diff changeset
76
anatofuz
parents:
diff changeset
77 // CHECK: [B1]
anatofuz
parents:
diff changeset
78 // CHECK-NEXT: 1: 5
anatofuz
parents:
diff changeset
79 // WARNINGS-NEXT: 2: [B1.1] (CXXConstructExpr, struct StructWithCopyConstructor)
anatofuz
parents:
diff changeset
80 // ANALYZER-NEXT: 2: [B1.1] (CXXConstructExpr, [B1.3], struct StructWithCopyConstructor)
anatofuz
parents:
diff changeset
81 // CHECK-NEXT: 3: StructWithCopyConstructor s(5) __attribute__((blocks("byref")));
anatofuz
parents:
diff changeset
82 // CHECK-NEXT: 4: ^{ }
anatofuz
parents:
diff changeset
83 // CHECK-NEXT: 5: (void)([B1.4]) (CStyleCastExpr, ToVoid, void)
anatofuz
parents:
diff changeset
84 // CHECK-NEXT: Preds (1): B2
anatofuz
parents:
diff changeset
85 // CHECK-NEXT: Succs (1): B0
anatofuz
parents:
diff changeset
86
anatofuz
parents:
diff changeset
87 // CHECK: [B0 (EXIT)]
anatofuz
parents:
diff changeset
88 // CHECK-NEXT: Preds (1): B1