1 // RUN: %clang_cc1 -fsyntax-only -analyze \
2 // RUN:   -analyzer-checker=core,debug.ExprInspection %s -verify
3 
4 // These test cases demonstrate lack of Static Analyzer features.
5 // The FIXME: tags indicate where we expect different output.
6 
7 // Handle constructors for default arguments.
8 // Default arguments in C++ are recomputed at every call,
9 // and are therefore local, and not static, variables.
10 void clang_analyzer_eval(bool);
11 void clang_analyzer_warnIfReached();
12 
13 struct init_with_list {
14   int a;
init_with_listinit_with_list15   init_with_list() : a(1) {}
16 };
17 
18 struct init_in_body {
19   int a;
init_in_bodyinit_in_body20   init_in_body() { a = 1; }
21 };
22 
23 struct init_default_member {
24   int a = 1;
25 };
26 
27 struct basic_struct {
28   int a;
29 };
30 
31 // Top-level analyzed functions.
top_f(init_with_list l=init_with_list ())32 void top_f(init_with_list l = init_with_list()) {
33   // We expect that the analyzer doesn't assume anything about the parameter.
34   clang_analyzer_eval(l.a == 1); // expected-warning {{TRUE}} expected-warning {{FALSE}}
35 }
36 
top_g(init_in_body l=init_in_body ())37 void top_g(init_in_body l = init_in_body()) {
38   // We expect that the analyzer doesn't assume anything about the parameter.
39   clang_analyzer_eval(l.a == 1); // expected-warning {{TRUE}} expected-warning {{FALSE}}
40 }
41 
top_h(init_default_member l=init_default_member ())42 void top_h(init_default_member l = init_default_member()) {
43   // We expect that the analyzer doesn't assume anything about the parameter.
44   clang_analyzer_eval(l.a == 1); // expected-warning {{TRUE}} expected-warning {{FALSE}}
45 }
46 
47 // Not-top-level analyzed functions.
called_f(init_with_list l=init_with_list ())48 int called_f(init_with_list l = init_with_list()) {
49   // We expect that the analyzer assumes the default value
50   // when called from test2().
51   return l.a;
52 }
53 
called_g(init_in_body l=init_in_body ())54 int called_g(init_in_body l = init_in_body()) {
55   // We expect that the analyzer assumes the default value
56   // when called from test3().
57   return l.a;
58 }
59 
called_h(init_default_member l=init_default_member ())60 int called_h(init_default_member l = init_default_member()) {
61   // We expect that the analyzer assumes the default value
62   // when called from test4().
63   return l.a;
64 }
65 
called_i(const init_with_list & l=init_with_list ())66 int called_i(const init_with_list &l = init_with_list()){
67   // We expect that the analyzer assumes the default value
68   // when called from test5().
69   return l.a;
70 }
71 
called_j(init_with_list && l=init_with_list ())72 int called_j(init_with_list &&l = init_with_list()){
73   // We expect that the analyzer assumes the default value
74   // when called from test6().
75   return l.a;
76 }
77 
plain_parameter_passing(basic_struct l)78 int plain_parameter_passing(basic_struct l) {
79   return l.a;
80 }
81 
test1()82 void test1() {
83   basic_struct b;
84   b.a = 1;
85   clang_analyzer_eval(plain_parameter_passing(b) == 1); //expected-warning {{TRUE}}
86 }
87 
test2()88 void test2() {
89   // We expect that the analyzer assumes the default value.
90   // FIXME: Should be TRUE.
91   clang_analyzer_eval(called_f() == 1); //expected-warning {{TRUE}} expected-warning {{FALSE}}
92 }
93 
test3()94 void test3() {
95   // We expect that the analyzer assumes the default value.
96   // FIXME: Should be TRUE.
97   clang_analyzer_eval(called_g() == 1); //expected-warning {{TRUE}} expected-warning {{FALSE}}
98 }
99 
test4()100 void test4() {
101   // We expect that the analyzer assumes the default value.
102   // FIXME: Should be TRUE.
103   clang_analyzer_eval(called_h() == 1); //expected-warning {{TRUE}} expected-warning {{FALSE}}
104 }
105 
test5()106 void test5() {
107   //We expect that the analyzer assumes the default value.
108   // FIXME: Should be TRUE.
109   clang_analyzer_eval(called_i() == 1); //expected-warning {{TRUE}} expected-warning {{FALSE}}
110 }
111 
test6()112 void test6() {
113   // We expect that the analyzer assumes the default value.
114   // FIXME: Should be TRUE.
115   clang_analyzer_eval(called_j() == 1); //expected-warning {{TRUE}} expected-warning {{FALSE}}
116 }
117