]> granicus.if.org Git - clang/commitdiff
Teach analyzer about cf_returns_not_retained for C functions.
authorTed Kremenek <kremenek@apple.com>
Wed, 25 May 2011 06:29:39 +0000 (06:29 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 25 May 2011 06:29:39 +0000 (06:29 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@132049 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Core/CFRefCount.cpp
test/Analysis/CFNumber.c

index 8478de590895e860c9ca56567807881e463b365c..59fea1031ffa824a89723042564fbf24a0bd7c4d 100644 (file)
@@ -1236,6 +1236,9 @@ RetainSummaryManager::updateSummaryFromAnnotations(RetainSummary &Summ,
     if (FD->getAttr<CFReturnsRetainedAttr>()) {
       Summ.setRetEffect(RetEffect::MakeOwned(RetEffect::CF, true));
     }
+    else if (FD->getAttr<CFReturnsNotRetainedAttr>()) {
+      Summ.setRetEffect(RetEffect::MakeNotOwned(RetEffect::CF));
+    }
   }
 }
 
index efdafcc80519fe182ca5314daaa0c46f8dc7dad3..11af0747a31735e52587eadb27e55be4bee08681 100644 (file)
@@ -26,6 +26,11 @@ __attribute__((cf_returns_retained)) CFNumberRef f2(unsigned short x) {
   return CFNumberCreate(0, kCFNumberSInt8Type, &x); // expected-warning{{A 16 bit integer is used to initialize a CFNumber object that represents an 8 bit integer. 8 bits of the input integer will be lost.}}
 }
 
+// test that the attribute overrides the naming convention.
+__attribute__((cf_returns_not_retained)) CFNumberRef CreateNum(unsigned char x) {
+  return CFNumberCreate(0, kCFNumberSInt8Type, &x); // expected-warning{{leak}}
+}
+
 CFNumberRef f3(unsigned i) {
   return CFNumberCreate(0, kCFNumberLongType, &i); // expected-warning{{A 32 bit integer is used to initialize a CFNumber object that represents a 64 bit integer.}}
 }