]> granicus.if.org Git - clang/commitdiff
[analyzer] Bug fix: do not report leaks for alloca()
authorAnton Yartsev <anton.yartsev@gmail.com>
Wed, 4 Mar 2015 23:18:21 +0000 (23:18 +0000)
committerAnton Yartsev <anton.yartsev@gmail.com>
Wed, 4 Mar 2015 23:18:21 +0000 (23:18 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@231314 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/MallocChecker.cpp
test/Analysis/malloc.c

index d77af6a4fb2b48b21147d2077d2479c3e70c1570..f2afcca971069855b1e3d367083026573f3c0f19 100644 (file)
@@ -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(
index 9c08bbcb1c0f46c2c9358ba6a9cbfa6873bfdb2a..5762061ba13eb24aa67b2990888b89eb6471018f 100644 (file)
@@ -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);