[cfe-commits] r49555 - in /cfe/trunk: lib/Analysis/CFRefCount.cpp test/Analysis-Apple/CFString.c
Ted Kremenek
kremenek at apple.com
Fri Apr 11 13:11:20 PDT 2008
Author: kremenek
Date: Fri Apr 11 15:11:19 2008
New Revision: 49555
URL: http://llvm.org/viewvc/llvm-project?rev=49555&view=rev
Log:
Changed behavior of how we handle "NULL" summaries: just call
GRSimpleVals::EvalCal(), and don't change reference counts.
Remove "getDoNothingSummary()", as a NULL summary does the same thing.
Added temporary hack for the "Get" rule for objects that return a pointer type:
treat them as non-owned CF objects.
Added test case to detect the release of a non-owned object.
Added:
cfe/trunk/test/Analysis-Apple/CFString.c
Modified:
cfe/trunk/lib/Analysis/CFRefCount.cpp
Modified: cfe/trunk/lib/Analysis/CFRefCount.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFRefCount.cpp?rev=49555&r1=49554&r2=49555&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Fri Apr 11 15:11:19 2008
@@ -136,7 +136,6 @@
CFRefSummary* getPersistentSummary(ArgEffects* AE, RetEffect RE);
- CFRefSummary* getDoNothingSummary(unsigned Args);
void FillDoNothing(unsigned Args);
@@ -366,16 +365,12 @@
ScratchArgs.push_back(DoNothing);
}
-CFRefSummary* CFRefSummaryManager::getDoNothingSummary(unsigned Args) {
- FillDoNothing(Args);
- return getPersistentSummary(getArgEffects(), RetEffect::MakeNoRet());
-}
CFRefSummary*
CFRefSummaryManager::getCFSummaryCreateRule(FunctionTypeProto* FT) {
if (!isCFRefType(FT->getResultType()))
- return getDoNothingSummary(FT->getNumArgs());
+ return NULL;
assert (ScratchArgs.empty());
@@ -389,8 +384,16 @@
CFRefSummary*
CFRefSummaryManager::getCFSummaryGetRule(FunctionTypeProto* FT) {
- if (!isCFRefType(FT->getResultType()))
- return getDoNothingSummary(FT->getNumArgs());
+ QualType RetTy = FT->getResultType();
+
+ // FIXME: For now we assume that all pointer types returned are referenced
+ // counted. Since this is the "Get" rule, we assume non-ownership, which
+ // works fine for things that are not reference counted. We do this because
+ // some generic data structures return "void*". We need something better
+ // in the future.
+
+ if (!isCFRefType(RetTy) && !RetTy->isPointerType())
+ return NULL;
assert (ScratchArgs.empty());
@@ -659,7 +662,7 @@
RefVal::Kind hasError = (RefVal::Kind) 0;
if (!Summ) {
-
+#if 0
// This function has no summary. Invalidate all reference-count state
// for arguments passed to this function, and also nuke the values of
// arguments passed-by-reference.
@@ -698,6 +701,10 @@
Builder.MakeNode(Dst, CE, Pred, St);
return;
+#else
+ GRSimpleVals::EvalCall(Dst, Eng, Builder, CE, L, Pred);
+ return;
+#endif
}
// This function has a summary. Evaluate the effect of the arguments.
Added: cfe/trunk/test/Analysis-Apple/CFString.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis-Apple/CFString.c?rev=49555&view=auto
==============================================================================
--- cfe/trunk/test/Analysis-Apple/CFString.c (added)
+++ cfe/trunk/test/Analysis-Apple/CFString.c Fri Apr 11 15:11:19 2008
@@ -0,0 +1,30 @@
+// RUN: clang -checker-cfref -verify %s
+
+#include <CoreFoundation/CFString.h>
+#include <CoreFoundation/CFArray.h>
+
+void f1() {
+
+ // Create the array.
+ CFMutableArrayRef A = CFArrayCreateMutable(NULL, 10, &kCFTypeArrayCallBacks);
+
+ // Create a string.
+ CFStringRef s1 = CFStringCreateWithCString(NULL, "hello world",
+ kCFStringEncodingUTF8);
+
+ // Add the string to the array.
+ CFArrayAppendValue(A, s1);
+
+ // Decrement the reference count.
+ CFRelease(s1); // no-warning
+
+ // Get the string. We don't own it.
+ s1 = (CFStringRef) CFArrayGetValueAtIndex(A, 0);
+
+ // Release the array.
+ CFRelease(A); // no-warning
+
+ // Release the string. This is a bug.
+ CFRelease(s1); // expected-warning{{Incorrect decrement of the reference count}}
+}
+
More information about the cfe-commits
mailing list