File: handle_constructors_for_default_arguments.cpp

package info (click to toggle)
llvm-toolchain-14 1%3A14.0.6-20
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,496,436 kB
  • sloc: cpp: 5,593,990; ansic: 986,873; asm: 585,869; python: 184,223; objc: 72,530; lisp: 31,119; f90: 27,793; javascript: 9,780; pascal: 9,762; sh: 9,482; perl: 7,468; ml: 5,432; awk: 3,523; makefile: 2,547; xml: 953; cs: 573; fortran: 567
file content (116 lines) | stat: -rw-r--r-- 3,419 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// RUN: %clang_cc1 -fsyntax-only -analyze \
// RUN:   -analyzer-checker=core,debug.ExprInspection %s -verify

// These test cases demonstrate lack of Static Analyzer features.
// The FIXME: tags indicate where we expect different output.

// Handle constructors for default arguments.
// Default arguments in C++ are recomputed at every call,
// and are therefore local, and not static, variables.
void clang_analyzer_eval(bool);
void clang_analyzer_warnIfReached();

struct init_with_list {
  int a;
  init_with_list() : a(1) {}
};

struct init_in_body {
  int a;
  init_in_body() { a = 1; }
};

struct init_default_member {
  int a = 1;
};

struct basic_struct {
  int a;
};

// Top-level analyzed functions.
void top_f(init_with_list l = init_with_list()) {
  // We expect that the analyzer doesn't assume anything about the parameter.
  clang_analyzer_eval(l.a == 1); // expected-warning {{TRUE}} expected-warning {{FALSE}}
}

void top_g(init_in_body l = init_in_body()) {
  // We expect that the analyzer doesn't assume anything about the parameter.
  clang_analyzer_eval(l.a == 1); // expected-warning {{TRUE}} expected-warning {{FALSE}}
}

void top_h(init_default_member l = init_default_member()) {
  // We expect that the analyzer doesn't assume anything about the parameter.
  clang_analyzer_eval(l.a == 1); // expected-warning {{TRUE}} expected-warning {{FALSE}}
}

// Not-top-level analyzed functions.
int called_f(init_with_list l = init_with_list()) {
  // We expect that the analyzer assumes the default value
  // when called from test2().
  return l.a;
}

int called_g(init_in_body l = init_in_body()) {
  // We expect that the analyzer assumes the default value
  // when called from test3().
  return l.a;
}

int called_h(init_default_member l = init_default_member()) {
  // We expect that the analyzer assumes the default value
  // when called from test4().
  return l.a;
}

int called_i(const init_with_list &l = init_with_list()){
  // We expect that the analyzer assumes the default value
  // when called from test5().
  return l.a;
}

int called_j(init_with_list &&l = init_with_list()){
  // We expect that the analyzer assumes the default value
  // when called from test6().
  return l.a;
}

int plain_parameter_passing(basic_struct l) {
  return l.a;
}

void test1() {
  basic_struct b;
  b.a = 1;
  clang_analyzer_eval(plain_parameter_passing(b) == 1); //expected-warning {{TRUE}}
}

void test2() {
  // We expect that the analyzer assumes the default value.
  // FIXME: Should be TRUE.
  clang_analyzer_eval(called_f() == 1); //expected-warning {{TRUE}} expected-warning {{FALSE}}
}

void test3() {
  // We expect that the analyzer assumes the default value.
  // FIXME: Should be TRUE.
  clang_analyzer_eval(called_g() == 1); //expected-warning {{TRUE}} expected-warning {{FALSE}}
}

void test4() {
  // We expect that the analyzer assumes the default value.
  // FIXME: Should be TRUE.
  clang_analyzer_eval(called_h() == 1); //expected-warning {{TRUE}} expected-warning {{FALSE}}
}

void test5() {
  //We expect that the analyzer assumes the default value.
  // FIXME: Should be TRUE.
  clang_analyzer_eval(called_i() == 1); //expected-warning {{TRUE}} expected-warning {{FALSE}}
}

void test6() {
  // We expect that the analyzer assumes the default value.
  // FIXME: Should be TRUE.
  clang_analyzer_eval(called_j() == 1); //expected-warning {{TRUE}} expected-warning {{FALSE}}
}