blob: de807fb3aad90d13854f2d684b0bd1833fbfa679 [file] [log] [blame]
Argyrios Kyrtzidisc4d2c902011-02-28 19:49:42 +00001// RUN: %clang_cc1 -analyze -analyzer-checker=core -analyzer-inline-call -analyzer-store region -verify %s
Zhongxing Xu1c625f22010-05-06 03:38:27 +00002
Ted Kremenekd4f482a2011-01-14 20:29:43 +00003int test1_f1() {
Zhongxing Xu06079d12010-02-27 02:44:37 +00004 int y = 1;
5 y++;
6 return y;
7}
8
Ted Kremenekd4f482a2011-01-14 20:29:43 +00009void test1_f2() {
Zhongxing Xu06079d12010-02-27 02:44:37 +000010 int x = 1;
Ted Kremenekd4f482a2011-01-14 20:29:43 +000011 x = test1_f1();
Zhongxing Xu06079d12010-02-27 02:44:37 +000012 if (x == 1) {
13 int *p = 0;
14 *p = 3; // no-warning
15 }
16 if (x == 2) {
17 int *p = 0;
Ted Kremenek452b84d2010-03-23 01:11:38 +000018 *p = 3; // expected-warning{{Dereference of null pointer (loaded from variable 'p')}}
Zhongxing Xu06079d12010-02-27 02:44:37 +000019 }
20}
Ted Kremenekd4f482a2011-01-14 20:29:43 +000021
22// Test that inlining works when the declared function has less arguments
23// than the actual number in the declaration.
24void test2_f1() {}
25int test2_f2();
26
27void test2_f3() {
28 test2_f1(test2_f2()); // expected-warning{{too many arguments in call to 'test2_f1'}}
29}
30
Ted Kremenek0849ade2012-01-12 19:25:46 +000031// Test that inlining works with recursive functions.
32
33unsigned factorial(unsigned x) {
34 if (x <= 1)
35 return 1;
36 return x * factorial(x - 1);
37}
38
39void test_factorial() {
40 if (factorial(3) == 6) {
41 int *p = 0;
42 *p = 0xDEADBEEF; // expected-warning {{null}}
43 }
44 else {
45 int *p = 0;
46 *p = 0xDEADBEEF; // no-warning
47 }
48}
49
50void test_factorial_2() {
51 unsigned x = factorial(3);
52 if (x == factorial(3)) {
53 int *p = 0;
54 *p = 0xDEADBEEF; // expected-warning {{null}}
55 }
56 else {
57 int *p = 0;
58 *p = 0xDEADBEEF; // no-warning
59 }
60}