1 // RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc,debug.ExprInspection -verify %s
2 // REQUIRES: LP64
3 
4 void clang_analyzer_eval(bool);
5 
6 int f1(char *dst) {
7   char *p = dst + 4;
8   char *q = dst + 3;
9   return !(q >= p);
10 }
11 
12 long f2(char *c) {
13   return long(c) & 1;
14 }
15 
16 bool f3() {
17   return !false;
18 }
19 
20 void *f4(int* w) {
21   return reinterpret_cast<void*&>(w);
22 }
23 
24 namespace {
25 
26 struct A { };
27 struct B {
28   operator A() { return A(); }
29 };
30 
31 A f(char *dst) {
32   B b;
33   return b;
34 }
35 
36 }
37 
38 namespace {
39 
40 struct S {
41     void *p;
42 };
43 
44 void *f(S* w) {
45     return &reinterpret_cast<void*&>(*w);
46 }
47 
48 }
49 
50 namespace {
51 
52 struct C {
53   void *p;
54   static void f();
55 };
56 
57 void C::f() { }
58 
59 }
60 
61 
62 void 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 
74 void useIntArray(int []);
75 void testIntArrayLiteral() {
76   useIntArray((int []){ 1, 2, 3 });
77 }
78 
79