1 // RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -verify %s
3 void clang_analyzer_eval(int);
4 void clang_analyzer_checkInlined(int);
9 clang_analyzer_checkInlined(1); // expected-warning{{TRUE}}
22 *p = 3; // expected-warning{{Dereference of null pointer (loaded from variable 'p')}}
26 // Test that inlining works when the declared function has less arguments
27 // than the actual number in the declaration.
32 test2_f1(test2_f2()); // expected-warning{{too many arguments in call to 'test2_f1'}}
35 // Test that inlining works with recursive functions.
37 unsigned factorial(unsigned x) {
40 return x * factorial(x - 1);
43 void test_factorial() {
44 if (factorial(3) == 6) {
46 *p = 0xDEADBEEF; // expected-warning {{null}}
50 *p = 0xDEADBEEF; // no-warning
54 void test_factorial_2() {
55 unsigned x = factorial(3);
56 if (x == factorial(3)) {
58 *p = 0xDEADBEEF; // expected-warning {{null}}
62 *p = 0xDEADBEEF; // no-warning
66 // Test that returning stack memory from a parent stack frame does
67 // not trigger a warning.
68 static char *return_buf(char *buf) {
72 void test_return_stack_memory_ok() {
74 char *pos = return_buf(stack_buf);
78 char *test_return_stack_memory_bad() {
81 return x; // expected-warning {{stack memory associated}}
84 // Test that passing a struct value with an uninitialized field does
85 // not trigger a warning if we are inlining and the body is available.
86 struct rdar10977037 { int x, y; };
87 int test_rdar10977037_aux(struct rdar10977037 v) { return v.y; }
88 int test_rdar10977037_aux_2(struct rdar10977037 v);
89 int test_rdar10977037() {
90 struct rdar10977037 v;
92 v. y += test_rdar10977037_aux(v); // no-warning
93 return test_rdar10977037_aux_2(v); // expected-warning {{Passed-by-value struct argument contains uninitialized data}}
97 // Test inlining a forward-declared function.
98 // This regressed when CallEvent was first introduced.
101 clang_analyzer_eval(plus1(2) == 3); // expected-warning{{TRUE}}
109 void never_called_by_anyone() {
110 clang_analyzer_checkInlined(0); // no-warning
114 void knr_one_argument(a) int a; { }
116 void call_with_less_arguments() {
117 knr_one_argument(); // expected-warning{{too few arguments}} expected-warning{{Function taking 1 argument}}