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