Clang Project

clang_source_code/test/Analysis/return-stmt-merge.cpp
1// RUN: %clang_analyze_cc1 -analyzer-checker=debug.AnalysisOrder,debug.ExprInspection -analyzer-config debug.AnalysisOrder:PreCall=true,debug.AnalysisOrder:PostCall=true,debug.AnalysisOrder:LiveSymbols=true %s 2>&1 | FileCheck %s
2
3// This test ensures that check::LiveSymbols is called as many times on the
4// path through the second "return" as it is through the first "return"
5// (three), and therefore the two paths were not merged prematurely before the
6// respective return statement is evaluated.
7// The paths would still be merged later, so we'd have only one post-call for
8// foo(), but it is incorrect to merge them in the middle of evaluating two
9// different statements.
10int coin();
11
12void foo() {
13  int x = coin();
14  if (x > 0)
15    return;
16  else
17    return;
18}
19
20void bar() {
21  foo();
22}
23
24// CHECK:      LiveSymbols
25// CHECK-NEXT: LiveSymbols
26// CHECK-NEXT: PreCall (foo)
27// CHECK-NEXT: LiveSymbols
28// CHECK-NEXT: LiveSymbols
29// CHECK-NEXT: PreCall (coin)
30// CHECK-NEXT: PostCall (coin)
31// CHECK-NEXT: LiveSymbols
32// CHECK-NEXT: LiveSymbols
33// CHECK-NEXT: LiveSymbols
34// CHECK-NEXT: PostCall (foo)
35// CHECK-NEXT: LiveSymbols
36// CHECK-NEXT: LiveSymbols
37// CHECK-NEXT: LiveSymbols
38