1// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-checker=core -fblocks -analyzer-opt-analyze-nested-blocks -verify -x objective-c++ %s
2// RUN: %clang_cc1 -std=c++11 -fsyntax-only -analyze -analyzer-checker=core,debug.DumpCFG -fblocks -analyzer-opt-analyze-nested-blocks  %s > %t 2>&1
3// RUN: FileCheck --input-file=%t %s
4
5// expected-no-diagnostics
6
7void testBlockWithoutCopyExpression(int i) {
8  // Captures i, with no copy expression.
9  (void)(^void() {
10    (void)i;
11  });
12}
13
14// CHECK-LABEL:void testBlockWithoutCopyExpression(int i)
15// CHECK-NEXT: [B2 (ENTRY)]
16// CHECK-NEXT:   Succs (1): B1
17
18// CHECK: [B1]
19// CHECK-NEXT:   1: ^{ }
20// CHECK-NEXT:   2: (void)([B1.1]) (CStyleCastExpr, ToVoid, void)
21// CHECK-NEXT:   Preds (1): B2
22// CHECK-NEXT:   Succs (1): B0
23
24// CHECK: [B0 (EXIT)]
25// CHECK-NEXT:   Preds (1): B1
26
27struct StructWithCopyConstructor {
28  StructWithCopyConstructor(int i);
29  StructWithCopyConstructor(const StructWithCopyConstructor &s);
30};
31void testBlockWithCopyExpression(StructWithCopyConstructor s) {
32  // Captures s, with a copy expression calling the copy constructor for StructWithCopyConstructor.
33  (void)(^void() {
34    (void)s;
35  });
36}
37
38// CHECK-LABEL:void testBlockWithCopyExpression(StructWithCopyConstructor s)
39// CHECK-NEXT: [B2 (ENTRY)]
40// CHECK-NEXT:   Succs (1): B1
41
42// CHECK: [B1]
43// CHECK-NEXT:   1: s
44// CHECK-NEXT:   2: [B1.1] (CXXConstructExpr, const struct StructWithCopyConstructor)
45// CHECK-NEXT:   3: ^{ }
46// CHECK-NEXT:   4: (void)([B1.3]) (CStyleCastExpr, ToVoid, void)
47// CHECK-NEXT:   Preds (1): B2
48// CHECK-NEXT:   Succs (1): B0
49
50// CHECK: [B0 (EXIT)]
51// CHECK-NEXT:   Preds (1): B1
52
53void testBlockWithCaptureByReference() {
54  __block StructWithCopyConstructor s(5);
55  // Captures s by reference, so no copy expression.
56  (void)(^void() {
57    (void)s;
58  });
59}
60
61// CHECK-LABEL:void testBlockWithCaptureByReference()
62// CHECK-NEXT: [B2 (ENTRY)]
63// CHECK-NEXT:   Succs (1): B1
64
65// CHECK: [B1]
66// CHECK-NEXT:   1: 5
67// CHECK-NEXT:   2: [B1.1] (CXXConstructExpr, struct StructWithCopyConstructor)
68// CHECK-NEXT:   3: StructWithCopyConstructor s(5) __attribute__((blocks("byref")));
69// CHECK-NEXT:   4: ^{ }
70// CHECK-NEXT:   5: (void)([B1.4]) (CStyleCastExpr, ToVoid, void)
71// CHECK-NEXT:   Preds (1): B2
72// CHECK-NEXT:   Succs (1): B0
73
74// CHECK: [B0 (EXIT)]
75// CHECK-NEXT:   Preds (1): B1
76