brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.2 KiB · 3ac11aa Raw
89 lines · plain
1// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core -fblocks -verify -x objective-c++ %s2// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,debug.DumpCFG -fblocks -analyzer-config cfg-rich-constructors=false %s > %t 2>&13// RUN: FileCheck --input-file=%t -check-prefixes=CHECK,WARNINGS %s4// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,debug.DumpCFG -fblocks -analyzer-config cfg-rich-constructors=true %s > %t 2>&15// RUN: FileCheck --input-file=%t -check-prefixes=CHECK,ANALYZER %s6 7// This file tests how we construct two different flavors of the Clang CFG -8// the CFG used by the Sema analysis-based warnings and the CFG used by the9// static analyzer. The difference in the behavior is checked via FileCheck10// prefixes (WARNINGS and ANALYZER respectively). When introducing new analyzer11// flags, no new run lines should be added - just these flags would go to the12// respective line depending on where is it turned on and where is it turned13// off. Feel free to add tests that test only one of the CFG flavors if you're14// not sure how the other flavor is supposed to work in your case.15 16// expected-no-diagnostics17 18void testBlockWithoutCopyExpression(int i) {19  // Captures i, with no copy expression.20  (void)(^void() {21    (void)i;22  });23}24 25// CHECK-LABEL:void testBlockWithoutCopyExpression(int i)26// CHECK-NEXT: [B2 (ENTRY)]27// CHECK-NEXT:   Succs (1): B128 29// CHECK: [B1]30// CHECK-NEXT:   1: ^{ }31// CHECK-NEXT:   2: (void)([B1.1]) (CStyleCastExpr, ToVoid, void)32// CHECK-NEXT:   Preds (1): B233// CHECK-NEXT:   Succs (1): B034 35// CHECK: [B0 (EXIT)]36// CHECK-NEXT:   Preds (1): B137 38struct StructWithCopyConstructor {39  StructWithCopyConstructor(int i);40  StructWithCopyConstructor(const StructWithCopyConstructor &s);41};42void testBlockWithCopyExpression(StructWithCopyConstructor s) {43  // Captures s, with a copy expression calling the copy constructor for StructWithCopyConstructor.44  (void)(^void() {45    (void)s;46  });47}48 49// CHECK-LABEL:void testBlockWithCopyExpression(StructWithCopyConstructor s)50// CHECK-NEXT: [B2 (ENTRY)]51// CHECK-NEXT:   Succs (1): B152 53// CHECK: [B1]54// CHECK-NEXT:   1: s55// CHECK-NEXT:   2: [B1.1] (ImplicitCastExpr, NoOp, const StructWithCopyConstructor)56// CHECK-NEXT:   3: [B1.2] (CXXConstructExpr, const StructWithCopyConstructor)57// CHECK-NEXT:   4: ^{ }58// CHECK-NEXT:   5: (void)([B1.4]) (CStyleCastExpr, ToVoid, void)59// CHECK-NEXT:   Preds (1): B260// CHECK-NEXT:   Succs (1): B061 62// CHECK: [B0 (EXIT)]63// CHECK-NEXT:   Preds (1): B164 65void testBlockWithCaptureByReference() {66  __block StructWithCopyConstructor s(5);67  // Captures s by reference, so no copy expression.68  (void)(^void() {69    (void)s;70  });71}72 73// CHECK-LABEL:void testBlockWithCaptureByReference()74// CHECK-NEXT: [B2 (ENTRY)]75// CHECK-NEXT:   Succs (1): B176 77// CHECK: [B1]78// CHECK-NEXT:   1: 579// WARNINGS-NEXT:   2: [B1.1] (CXXConstructExpr, StructWithCopyConstructor)80// ANALYZER-NEXT:   2: [B1.1] (CXXConstructExpr, [B1.3], StructWithCopyConstructor)81// CHECK-NEXT:   3: __attribute__((blocks("byref"))) StructWithCopyConstructor s(5);82// CHECK-NEXT:   4: ^{ }83// CHECK-NEXT:   5: (void)([B1.4]) (CStyleCastExpr, ToVoid, void)84// CHECK-NEXT:   Preds (1): B285// CHECK-NEXT:   Succs (1): B086 87// CHECK: [B0 (EXIT)]88// CHECK-NEXT:   Preds (1): B189