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