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