Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Analysis / handle_constructors_for_default_arguments.cpp
blobc54d86526ec74db966acfb513a960b299e8732e1
1 // RUN: %clang_cc1 -fsyntax-only -analyze \
2 // RUN: -analyzer-checker=core,debug.ExprInspection %s -verify
4 // These test cases demonstrate lack of Static Analyzer features.
5 // The FIXME: tags indicate where we expect different output.
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();
13 struct init_with_list {
14 int a;
15 init_with_list() : a(1) {}
18 struct init_in_body {
19 int a;
20 init_in_body() { a = 1; }
23 struct init_default_member {
24 int a = 1;
27 struct basic_struct {
28 int a;
31 // Top-level analyzed functions.
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}}
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}}
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}}
47 // Not-top-level analyzed functions.
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;
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;
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;
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;
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;
78 int plain_parameter_passing(basic_struct l) {
79 return l.a;
82 void test1() {
83 basic_struct b;
84 b.a = 1;
85 clang_analyzer_eval(plain_parameter_passing(b) == 1); //expected-warning {{TRUE}}
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}}
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}}
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}}
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}}
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}}