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 f1(char * dst)6int f1(char *dst) { 7 char *p = dst + 4; 8 char *q = dst + 3; 9 return !(q >= p); 10 } 11 f2(char * c)12long f2(char *c) { 13 return long(c) & 1; 14 } 15 f3()16bool f3() { 17 return !false; 18 } 19 f4(int * w)20void *f4(int* w) { 21 return reinterpret_cast<void*&>(w); 22 } 23 24 namespace { 25 26 struct A { }; 27 struct B { operator A__anona551cda10111::B28 operator A() { return A(); } 29 }; 30 f(char * dst)31A f(char *dst) { 32 B b; 33 return b; 34 } 35 36 } 37 38 namespace { 39 40 struct S { 41 void *p; 42 }; 43 f(S * w)44void *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 f()57void C::f() { } 58 59 } 60 61 vla(int n)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 74 void useIntArray(int []); testIntArrayLiteral()75void testIntArrayLiteral() { 76 useIntArray((int []){ 1, 2, 3 }); 77 } 78 79