[analyzer] Trust summaries for OSObject::retain and OSObject::release
Refactor the way in which summaries are consumed for safeMetaCast
Differential Revision: https://reviews.llvm.org/D53549
llvm-svn: 345099
diff --git a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
index 8585a02..578f282 100644
--- a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
@@ -776,31 +776,27 @@
const LocationContext *LCtx = C.getLocationContext();
- // Process OSDynamicCast: should just return the first argument.
- // For now, tresting the cast as a no-op, and disregarding the case where
- // the output becomes null due to the type mismatch.
- if (FD->getNameAsString() == "safeMetaCast") {
- state = state->BindExpr(CE, LCtx,
- state->getSVal(CE->getArg(0), LCtx));
- C.addTransition(state);
- return true;
- }
-
// See if it's one of the specific functions we know how to eval.
if (!SmrMgr.canEval(CE, FD, hasTrustedImplementationAnnotation))
return false;
// Bind the return value.
- SVal RetVal = state->getSVal(CE->getArg(0), LCtx);
- if (RetVal.isUnknown() ||
- (hasTrustedImplementationAnnotation && !ResultTy.isNull())) {
+ // For now, all the functions which we can evaluate and which take
+ // at least one argument are identities.
+ if (CE->getNumArgs() >= 1) {
+ SVal RetVal = state->getSVal(CE->getArg(0), LCtx);
+
// If the receiver is unknown or the function has
// 'rc_ownership_trusted_implementation' annotate attribute, conjure a
// return value.
- SValBuilder &SVB = C.getSValBuilder();
- RetVal = SVB.conjureSymbolVal(nullptr, CE, LCtx, ResultTy, C.blockCount());
+ if (RetVal.isUnknown() ||
+ (hasTrustedImplementationAnnotation && !ResultTy.isNull())) {
+ SValBuilder &SVB = C.getSValBuilder();
+ RetVal =
+ SVB.conjureSymbolVal(nullptr, CE, LCtx, ResultTy, C.blockCount());
+ }
+ state = state->BindExpr(CE, LCtx, RetVal, false);
}
- state = state->BindExpr(CE, LCtx, RetVal, false);
C.addTransition(state);
return true;