From d1e015eb441910937c74d489970322a3a3491a67 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Wed, 25 May 2011 06:29:39 +0000 Subject: [PATCH] Teach analyzer about cf_returns_not_retained for C functions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@132049 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/StaticAnalyzer/Core/CFRefCount.cpp | 3 +++ test/Analysis/CFNumber.c | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/lib/StaticAnalyzer/Core/CFRefCount.cpp b/lib/StaticAnalyzer/Core/CFRefCount.cpp index 8478de5908..59fea1031f 100644 --- a/lib/StaticAnalyzer/Core/CFRefCount.cpp +++ b/lib/StaticAnalyzer/Core/CFRefCount.cpp @@ -1236,6 +1236,9 @@ RetainSummaryManager::updateSummaryFromAnnotations(RetainSummary &Summ, if (FD->getAttr()) { Summ.setRetEffect(RetEffect::MakeOwned(RetEffect::CF, true)); } + else if (FD->getAttr()) { + Summ.setRetEffect(RetEffect::MakeNotOwned(RetEffect::CF)); + } } } diff --git a/test/Analysis/CFNumber.c b/test/Analysis/CFNumber.c index efdafcc805..11af0747a3 100644 --- a/test/Analysis/CFNumber.c +++ b/test/Analysis/CFNumber.c @@ -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.}} } -- 2.50.1