[llvm-branch-commits] [cfe-branch] r167797 - in /cfe/branches/release_32: ./ lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp test/Analysis/inlining/InlineObjCInstanceMethod.m test/SemaCXX/warn-unreachable.cpp
Anna Zaks
ganna at apple.com
Mon Nov 12 16:48:20 PST 2012
Author: zaks
Date: Mon Nov 12 18:48:20 2012
New Revision: 167797
URL: http://llvm.org/viewvc/llvm-project?rev=167797&view=rev
Log:
[analyzer] Follow up to r167762 - precisely determine the adjustment
conditions.
The adjustment is needed only in case of dynamic dispatch performed by
the analyzer - when the runtime declaration is different from the static
one.
Document this explicitly in the code (by adding a helper). Also, use
canonical Decls to avoid matching against the case where the definition
is different from found declaration.
This fix suppresses the testcase I added in r167762, so add another
testcase to make sure we do test commit r167762.
Modified:
cfe/branches/release_32/ (props changed)
cfe/branches/release_32/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
cfe/branches/release_32/test/Analysis/inlining/InlineObjCInstanceMethod.m
cfe/branches/release_32/test/SemaCXX/warn-unreachable.cpp (props changed)
Propchange: cfe/branches/release_32/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Nov 12 18:48:20 2012
@@ -1,3 +1,3 @@
/cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:167749,167762,167788
+/cfe/trunk:167749,167762,167780,167788,167790
/cfe/trunk/test/SemaTemplate:126920
Modified: cfe/branches/release_32/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_32/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp?rev=167797&r1=167796&r2=167797&view=diff
==============================================================================
--- cfe/branches/release_32/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp (original)
+++ cfe/branches/release_32/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp Mon Nov 12 18:48:20 2012
@@ -191,6 +191,16 @@
currBldrCtx = 0;
}
+static bool wasDifferentDeclUsedForInlining(CallEventRef<> Call,
+ const StackFrameContext *calleeCtx) {
+ const Decl *RuntimeCallee = calleeCtx->getDecl();
+ const Decl *StaticDecl = Call->getDecl();
+ assert(RuntimeCallee);
+ if (!StaticDecl)
+ return true;
+ return RuntimeCallee->getCanonicalDecl() != StaticDecl->getCanonicalDecl();
+}
+
/// The call exit is simulated with a sequence of nodes, which occur between
/// CallExitBegin and CallExitEnd. The following operations occur between the
/// two program points:
@@ -230,9 +240,10 @@
const LocationContext *LCtx = CEBNode->getLocationContext();
SVal V = state->getSVal(RS, LCtx);
- const Decl *Callee = calleeCtx->getDecl();
- if (Callee != Call->getDecl()) {
- QualType ReturnedTy = CallEvent::getDeclaredResultType(Callee);
+ // Ensure that the return type matches the type of the returned Expr.
+ if (wasDifferentDeclUsedForInlining(Call, calleeCtx)) {
+ QualType ReturnedTy =
+ CallEvent::getDeclaredResultType(calleeCtx->getDecl());
if (!ReturnedTy.isNull()) {
if (const Expr *Ex = dyn_cast<Expr>(CE)) {
V = adjustReturnValue(V, Ex->getType(), ReturnedTy,
Modified: cfe/branches/release_32/test/Analysis/inlining/InlineObjCInstanceMethod.m
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_32/test/Analysis/inlining/InlineObjCInstanceMethod.m?rev=167797&r1=167796&r2=167797&view=diff
==============================================================================
--- cfe/branches/release_32/test/Analysis/inlining/InlineObjCInstanceMethod.m (original)
+++ cfe/branches/release_32/test/Analysis/inlining/InlineObjCInstanceMethod.m Mon Nov 12 18:48:20 2012
@@ -1,15 +1,32 @@
-// RUN: %clang --analyze -Xanalyzer -analyzer-checker=osx.cocoa.IncompatibleMethodTypes -Xclang -verify %s
+// RUN: %clang --analyze -Xanalyzer -analyzer-checker=osx.cocoa.IncompatibleMethodTypes,osx.coreFoundation.CFRetainRelease -Xclang -verify %s
#include "InlineObjCInstanceMethod.h"
+typedef const struct __CFString * CFStringRef;
+typedef const void * CFTypeRef;
+extern CFTypeRef CFRetain(CFTypeRef cf);
+extern void CFRelease(CFTypeRef cf);
+extern CFStringRef getString(void);
+
// Method is defined in the parent; called through self.
@interface MyParent : NSObject
- (int)getInt;
+- (const struct __CFString *) testCovariantReturnType __attribute__((cf_returns_retained));
@end
@implementation MyParent
- (int)getInt {
return 0;
}
+
+- (CFStringRef) testCovariantReturnType __attribute__((cf_returns_retained)) {
+ CFStringRef Str = ((void*)0);
+ Str = getString();
+ if (Str) {
+ CFRetain(Str);
+ }
+ return Str;
+}
+
@end
@interface MyClass : MyParent
@@ -88,12 +105,22 @@
@interface EvilChild : MyParent
- (id)getInt;
+- (const struct __CFString *) testCovariantReturnType __attribute__((cf_returns_retained));
@end
@implementation EvilChild
- (id)getInt { // expected-warning {{types are incompatible}}
return self;
}
+- (CFStringRef) testCovariantReturnType __attribute__((cf_returns_retained)) {
+ CFStringRef Str = ((void*)0);
+ Str = getString();
+ if (Str) {
+ CFRetain(Str);
+ }
+ return Str;
+}
+
@end
int testNonCovariantReturnType() {
@@ -109,3 +136,13 @@
[obj release];
return 5/(x-1); // no-warning
}
+
+int testCovariantReturnTypeNoErrorSinceTypesMatch() {
+ MyParent *obj = [[EvilChild alloc] init];
+
+ CFStringRef S = ((void*)0);
+ S = [obj testCovariantReturnType];
+ if (S)
+ CFRelease(S);
+ CFRelease(obj);
+}
Propchange: cfe/branches/release_32/test/SemaCXX/warn-unreachable.cpp
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Nov 12 18:48:20 2012
@@ -1,2 +1,2 @@
/cfe/branches/type-system-rewrite/test/SemaCXX/warn-unreachable.cpp:134693-134817
-/cfe/trunk/test/SemaCXX/warn-unreachable.cpp:121961,167749,167762,167788
+/cfe/trunk/test/SemaCXX/warn-unreachable.cpp:121961,167749,167762,167780,167788,167790
More information about the llvm-branch-commits
mailing list