diff --git a/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/lib/StaticAnalyzer/Checkers/MallocChecker.cpp index d77af6a4fb2b48b21147d2077d2479c3e70c1570..f2afcca971069855b1e3d367083026573f3c0f19 100644 --- a/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -1934,6 +1934,11 @@ void MallocChecker::reportLeak(SymbolRef Sym, ExplodedNode *N, if (!CheckKind.hasValue()) return; + const RefState *RS = C.getState()->get<RegionState>(Sym); + assert(RS); + if (RS->getAllocationFamily() == AF_Alloca) + return; + assert(N); if (!BT_Leak[*CheckKind]) { BT_Leak[*CheckKind].reset( diff --git a/test/Analysis/malloc.c b/test/Analysis/malloc.c index 9c08bbcb1c0f46c2c9358ba6a9cbfa6873bfdb2a..5762061ba13eb24aa67b2990888b89eb6471018f 100644 --- a/test/Analysis/malloc.c +++ b/test/Analysis/malloc.c @@ -6,6 +6,7 @@ void clang_analyzer_eval(int); typedef __typeof(sizeof(int)) size_t; void *malloc(size_t); +void *alloca(size_t); void *valloc(size_t); void free(void *); void *realloc(void *ptr, size_t size); @@ -50,6 +51,14 @@ void reallocNotNullPtr(unsigned sizeIn) { } } +void allocaTest() { + int *p = alloca(sizeof(int)); +} // no warn + +void allocaBuiltinTest() { + int *p = __builtin_alloca(sizeof(int)); +} // no warn + int *realloctest1() { int *q = malloc(12); q = realloc(q, 20);