[cfe-commits] r134493 - in /cfe/trunk: include/clang/Analysis/DomainSpecific/CocoaConventions.h lib/Analysis/CocoaConventions.cpp lib/StaticAnalyzer/Core/CFRefCount.cpp test/Analysis/retain-release.m
Ted Kremenek
kremenek at apple.com
Wed Jul 13 20:55:44 PDT 2011
Awesome!
Sent from my iPad
On Jul 6, 2011, at 9:00 AM, Douglas Gregor <dgregor at apple.com> wrote:
> Author: dgregor
> Date: Wed Jul 6 11:00:34 2011
> New Revision: 134493
>
> URL: http://llvm.org/viewvc/llvm-project?rev=134493&view=rev
> Log:
> Teach the static analyzer's interpretation of Cocoa conventions to
> obey the objc_method_family attribute when provided. Fixes
> <rdar://problem/9726279>.
>
> Modified:
> cfe/trunk/include/clang/Analysis/DomainSpecific/CocoaConventions.h
> cfe/trunk/lib/Analysis/CocoaConventions.cpp
> cfe/trunk/lib/StaticAnalyzer/Core/CFRefCount.cpp
> cfe/trunk/test/Analysis/retain-release.m
>
> Modified: cfe/trunk/include/clang/Analysis/DomainSpecific/CocoaConventions.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/DomainSpecific/CocoaConventions.h?rev=134493&r1=134492&r2=134493&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Analysis/DomainSpecific/CocoaConventions.h (original)
> +++ cfe/trunk/include/clang/Analysis/DomainSpecific/CocoaConventions.h Wed Jul 6 11:00:34 2011
> @@ -17,15 +17,19 @@
> #include "clang/AST/Type.h"
>
> namespace clang {
> +
> +class ObjCMethodDecl;
> +
> namespace ento {
> namespace cocoa {
>
> enum NamingConvention { NoConvention, CreateRule, InitRule };
>
> - NamingConvention deriveNamingConvention(Selector S);
> + NamingConvention deriveNamingConvention(Selector S, const ObjCMethodDecl *MD);
>
> - static inline bool followsFundamentalRule(Selector S) {
> - return deriveNamingConvention(S) == CreateRule;
> + static inline bool followsFundamentalRule(Selector S,
> + const ObjCMethodDecl *MD) {
> + return deriveNamingConvention(S, MD) == CreateRule;
> }
>
> bool isRefType(QualType RetTy, llvm::StringRef Prefix,
>
> Modified: cfe/trunk/lib/Analysis/CocoaConventions.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CocoaConventions.cpp?rev=134493&r1=134492&r2=134493&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Analysis/CocoaConventions.cpp (original)
> +++ cfe/trunk/lib/Analysis/CocoaConventions.cpp Wed Jul 6 11:00:34 2011
> @@ -36,8 +36,10 @@
> // not release it."
> //
>
> -cocoa::NamingConvention cocoa::deriveNamingConvention(Selector S) {
> - switch (S.getMethodFamily()) {
> +cocoa::NamingConvention cocoa::deriveNamingConvention(Selector S,
> + const ObjCMethodDecl *MD) {
> + switch (MD && MD->hasAttr<ObjCMethodFamilyAttr>()? MD->getMethodFamily()
> + : S.getMethodFamily()) {
> case OMF_None:
> case OMF_autorelease:
> case OMF_dealloc:
>
> Modified: cfe/trunk/lib/StaticAnalyzer/Core/CFRefCount.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/CFRefCount.cpp?rev=134493&r1=134492&r2=134493&view=diff
> ==============================================================================
> --- cfe/trunk/lib/StaticAnalyzer/Core/CFRefCount.cpp (original)
> +++ cfe/trunk/lib/StaticAnalyzer/Core/CFRefCount.cpp Wed Jul 6 11:00:34 2011
> @@ -1349,7 +1349,7 @@
> if (cocoa::isCocoaObjectRef(RetTy)) {
> // EXPERIMENTAL: assume the Cocoa conventions for all objects returned
> // by instance methods.
> - RetEffect E = cocoa::followsFundamentalRule(S)
> + RetEffect E = cocoa::followsFundamentalRule(S, MD)
> ? ObjCAllocRetE : RetEffect::MakeNotOwned(RetEffect::ObjC);
>
> return getPersistentSummary(E, ReceiverEff, MayEscape);
> @@ -1357,7 +1357,7 @@
>
> // Look for methods that return an owned core foundation object.
> if (cocoa::isCFObjectRef(RetTy)) {
> - RetEffect E = cocoa::followsFundamentalRule(S)
> + RetEffect E = cocoa::followsFundamentalRule(S, MD)
> ? RetEffect::MakeOwned(RetEffect::CF, true)
> : RetEffect::MakeNotOwned(RetEffect::CF);
>
> @@ -1428,7 +1428,7 @@
> assert(ScratchArgs.isEmpty());
>
> // "initXXX": pass-through for receiver.
> - if (cocoa::deriveNamingConvention(S) == cocoa::InitRule)
> + if (cocoa::deriveNamingConvention(S, MD) == cocoa::InitRule)
> Summ = getInitMethodSummary(RetTy);
> else
> Summ = getCommonMethodSummary(MD, S, RetTy);
>
> Modified: cfe/trunk/test/Analysis/retain-release.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/retain-release.m?rev=134493&r1=134492&r2=134493&view=diff
> ==============================================================================
> --- cfe/trunk/test/Analysis/retain-release.m (original)
> +++ cfe/trunk/test/Analysis/retain-release.m Wed Jul 6 11:00:34 2011
> @@ -1462,3 +1462,28 @@
> void rdar_9234108() {
> rdar_9234108_helper(0, CFStringCreate());
> }
> +
> +// <rdar://problem/9726279> - Make sure that objc_method_family works
> +// to override naming conventions.
> +struct TwoDoubles {
> + double one;
> + double two;
> +};
> +typedef struct TwoDoubles TwoDoubles;
> +
> + at interface NSValue (Mine)
> +- (id)_prefix_initWithTwoDoubles:(TwoDoubles)twoDoubles __attribute__((objc_method_family(init)));
> + at end
> +
> + at implementation NSValue (Mine)
> +- (id)_prefix_initWithTwoDoubles:(TwoDoubles)twoDoubles
> +{
> + return [self init];
> +}
> + at end
> +
> +void rdar9726279() {
> + TwoDoubles twoDoubles = { 0.0, 0.0 };
> + NSValue *value = [[NSValue alloc] _prefix_initWithTwoDoubles:twoDoubles];
> + [value release];
> +}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list