r231314 - [analyzer] Bug fix: do not report leaks for alloca()

Anton Yartsev anton.yartsev at gmail.com
Wed Mar 4 15:18:21 PST 2015


Author: ayartsev
Date: Wed Mar  4 17:18:21 2015
New Revision: 231314

URL: http://llvm.org/viewvc/llvm-project?rev=231314&view=rev
Log:
[analyzer] Bug fix: do not report leaks for alloca()

Modified:
    cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
    cfe/trunk/test/Analysis/malloc.c

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp?rev=231314&r1=231313&r2=231314&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp Wed Mar  4 17:18:21 2015
@@ -1934,6 +1934,11 @@ void MallocChecker::reportLeak(SymbolRef
   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(

Modified: cfe/trunk/test/Analysis/malloc.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/malloc.c?rev=231314&r1=231313&r2=231314&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/malloc.c (original)
+++ cfe/trunk/test/Analysis/malloc.c Wed Mar  4 17:18:21 2015
@@ -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);





More information about the cfe-commits mailing list