blob: 8912bf68de3fff49da4cb034ade151a0c4392feb [file] [log] [blame]
Jordan Rose9955e702012-06-16 01:28:00 +00001// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc,debug.ExprInspection -verify %s
2
3void clang_analyzer_eval(bool);
Argyrios Kyrtzidisf4699d12011-02-18 20:55:19 +00004
5int f1(char *dst) {
6 char *p = dst + 4;
7 char *q = dst + 3;
8 return !(q >= p);
9}
Argyrios Kyrtzidis4f20de12011-02-18 21:24:56 +000010
Argyrios Kyrtzidis7ff07dc2011-02-19 01:08:41 +000011long f2(char *c) {
12 return long(c) & 1;
13}
14
Argyrios Kyrtzidis370e6e92011-02-19 01:59:41 +000015bool f3() {
16 return !false;
17}
18
Argyrios Kyrtzidisb14175a2011-02-19 08:03:18 +000019void *f4(int* w) {
20 return reinterpret_cast<void*&>(w);
21}
22
Argyrios Kyrtzidis4f20de12011-02-18 21:24:56 +000023namespace {
24
25struct A { };
26struct B {
John McCall15e310a2011-02-19 02:53:41 +000027 operator A() { return A(); }
Argyrios Kyrtzidis4f20de12011-02-18 21:24:56 +000028};
29
30A f(char *dst) {
31 B b;
32 return b;
33}
34
35}
Argyrios Kyrtzidisb14175a2011-02-19 08:03:18 +000036
37namespace {
38
39struct S {
40 void *p;
41};
42
43void *f(S* w) {
44 return &reinterpret_cast<void*&>(*w);
45}
46
47}
Anders Carlsson65b427f2011-03-26 14:30:44 +000048
49namespace {
50
51struct C {
52 void *p;
53 static void f();
54};
55
56void C::f() { }
57
58}
Jordan Rose9955e702012-06-16 01:28:00 +000059
60
61void vla(int n) {
62 int nums[n];
63 nums[0] = 1;
64 clang_analyzer_eval(nums[0] == 1); // expected-warning{{TRUE}}
65
66 // This used to fail with MallocChecker on, and /only/ in C++ mode.
67 // This struct is POD, though, so it should be fine to put it in a VLA.
68 struct { int x; } structs[n];
69 structs[0].x = 1;
70 clang_analyzer_eval(structs[0].x == 1); // expected-warning{{TRUE}}
71}
72
Jordan Rose3083d3c2012-06-16 01:28:03 +000073void useIntArray(int []);
74void testIntArrayLiteral() {
75 useIntArray((int []){ 1, 2, 3 });
76}
77