1*0a6a1f1dSLionel Sambuc // RUN: %clang -target x86_64-unknown-linux --analyze %s 2*0a6a1f1dSLionel Sambuc 3*0a6a1f1dSLionel Sambuc #include "Inputs/system-header-simulator.h" 4*0a6a1f1dSLionel Sambuc 5*0a6a1f1dSLionel Sambuc #define __GFP_ZERO 0x8000 6*0a6a1f1dSLionel Sambuc #define NULL ((void *)0) 7*0a6a1f1dSLionel Sambuc 8*0a6a1f1dSLionel Sambuc void *kmalloc(size_t, int); 9*0a6a1f1dSLionel Sambuc 10*0a6a1f1dSLionel Sambuc struct test { 11*0a6a1f1dSLionel Sambuc }; 12*0a6a1f1dSLionel Sambuc 13*0a6a1f1dSLionel Sambuc void foo(struct test *); 14*0a6a1f1dSLionel Sambuc test_zeroed()15*0a6a1f1dSLionel Sambucvoid test_zeroed() { 16*0a6a1f1dSLionel Sambuc struct test **list, *t; 17*0a6a1f1dSLionel Sambuc int i; 18*0a6a1f1dSLionel Sambuc 19*0a6a1f1dSLionel Sambuc list = kmalloc(sizeof(*list) * 10, __GFP_ZERO); 20*0a6a1f1dSLionel Sambuc if (list == NULL) 21*0a6a1f1dSLionel Sambuc return; 22*0a6a1f1dSLionel Sambuc 23*0a6a1f1dSLionel Sambuc for (i = 0; i < 10; i++) { 24*0a6a1f1dSLionel Sambuc t = list[i]; 25*0a6a1f1dSLionel Sambuc foo(t); 26*0a6a1f1dSLionel Sambuc } 27*0a6a1f1dSLionel Sambuc free(list); // no-warning 28*0a6a1f1dSLionel Sambuc } 29*0a6a1f1dSLionel Sambuc test_nonzero()30*0a6a1f1dSLionel Sambucvoid test_nonzero() { 31*0a6a1f1dSLionel Sambuc struct test **list, *t; 32*0a6a1f1dSLionel Sambuc int i; 33*0a6a1f1dSLionel Sambuc 34*0a6a1f1dSLionel Sambuc list = kmalloc(sizeof(*list) * 10, 0); 35*0a6a1f1dSLionel Sambuc if (list == NULL) 36*0a6a1f1dSLionel Sambuc return; 37*0a6a1f1dSLionel Sambuc 38*0a6a1f1dSLionel Sambuc for (i = 0; i < 10; i++) { 39*0a6a1f1dSLionel Sambuc t = list[i]; // expected-warning{{undefined}} 40*0a6a1f1dSLionel Sambuc foo(t); 41*0a6a1f1dSLionel Sambuc } 42*0a6a1f1dSLionel Sambuc free(list); 43*0a6a1f1dSLionel Sambuc } 44*0a6a1f1dSLionel Sambuc test_indeterminate(int flags)45*0a6a1f1dSLionel Sambucvoid test_indeterminate(int flags) { 46*0a6a1f1dSLionel Sambuc struct test **list, *t; 47*0a6a1f1dSLionel Sambuc int i; 48*0a6a1f1dSLionel Sambuc 49*0a6a1f1dSLionel Sambuc list = kmalloc(sizeof(*list) * 10, flags); 50*0a6a1f1dSLionel Sambuc if (list == NULL) 51*0a6a1f1dSLionel Sambuc return; 52*0a6a1f1dSLionel Sambuc 53*0a6a1f1dSLionel Sambuc for (i = 0; i < 10; i++) { 54*0a6a1f1dSLionel Sambuc t = list[i]; // expected-warning{{undefined}} 55*0a6a1f1dSLionel Sambuc foo(t); 56*0a6a1f1dSLionel Sambuc } 57*0a6a1f1dSLionel Sambuc free(list); 58*0a6a1f1dSLionel Sambuc } 59