[cfe-commits] r151840 - in /cfe/trunk: lib/StaticAnalyzer/Checkers/MallocChecker.cpp test/Analysis/malloc-annotations.c
Anna Zaks
ganna at apple.com
Thu Mar 1 14:06:06 PST 2012
Author: zaks
Date: Thu Mar 1 16:06:06 2012
New Revision: 151840
URL: http://llvm.org/viewvc/llvm-project?rev=151840&view=rev
Log:
[analyzer] Fix a regression introduced in malloc with
attributes, introduced in r151188.
+ the test to catch it.
Thanks to Ahmed Charles for pointing this out.
Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
cfe/trunk/test/Analysis/malloc-annotations.c
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp?rev=151840&r1=151839&r2=151840&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp Thu Mar 1 16:06:06 2012
@@ -442,12 +442,16 @@
if (Att->getModule() != "malloc")
return 0;
+ ProgramStateRef State = C.getState();
+
for (OwnershipAttr::args_iterator I = Att->args_begin(), E = Att->args_end();
I != E; ++I) {
- return FreeMemAux(C, CE, C.getState(), *I,
- Att->getOwnKind() == OwnershipAttr::Holds);
+ ProgramStateRef StateI = FreeMemAux(C, CE, State, *I,
+ Att->getOwnKind() == OwnershipAttr::Holds);
+ if (StateI)
+ State = StateI;
}
- return 0;
+ return State;
}
ProgramStateRef MallocChecker::FreeMemAux(CheckerContext &C,
Modified: cfe/trunk/test/Analysis/malloc-annotations.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/malloc-annotations.c?rev=151840&r1=151839&r2=151840&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/malloc-annotations.c (original)
+++ cfe/trunk/test/Analysis/malloc-annotations.c Thu Mar 1 16:06:06 2012
@@ -6,6 +6,8 @@
void *calloc(size_t nmemb, size_t size);
void __attribute((ownership_returns(malloc))) *my_malloc(size_t);
void __attribute((ownership_takes(malloc, 1))) my_free(void *);
+void my_freeBoth(void *, void *)
+ __attribute((ownership_holds(malloc, 1, 2)));
void __attribute((ownership_returns(malloc, 1))) *my_malloc2(size_t);
void __attribute((ownership_holds(malloc, 1))) my_hold(void *);
@@ -260,3 +262,10 @@
}
return result; // expected-warning{{never released}}
}
+
+void testMultipleFreeAnnotations() {
+ int *p = malloc(12);
+ int *q = malloc(12);
+ my_freeBoth(p, q);
+}
+
More information about the cfe-commits
mailing list