1 // RUN: %clang_cc1 -analyze -analyzer-checker=core,unix,core.uninitialized -analyzer-store=region -verify -analyzer-config unix:Optimistic=true %s 2 typedef __typeof(sizeof(int)) size_t; 3 void *malloc(size_t); 4 void free(void *); 5 stackBased1()6char stackBased1 () { 7 char buf[2]; 8 buf[0] = 'a'; 9 return buf[1]; // expected-warning{{Undefined}} 10 } 11 stackBased2()12char stackBased2 () { 13 char buf[2]; 14 buf[1] = 'a'; 15 return buf[0]; // expected-warning{{Undefined}} 16 } 17 18 // Exercise the conditional visitor. Radar://10105448 stackBased3(int * x)19char stackBased3 (int *x) { 20 char buf[2]; 21 int *y; 22 buf[0] = 'a'; 23 if (!(y = x)) { 24 return buf[1]; // expected-warning{{Undefined}} 25 } 26 return buf[0]; 27 } 28 heapBased1()29char heapBased1 () { 30 char *buf = malloc(2); 31 buf[0] = 'a'; 32 char result = buf[1]; // expected-warning{{undefined}} 33 free(buf); 34 return result; 35 } 36 heapBased2()37char heapBased2 () { 38 char *buf = malloc(2); 39 buf[1] = 'a'; 40 char result = buf[0]; // expected-warning{{undefined}} 41 free(buf); 42 return result; 43 } 44