r375328 - [analyzer] Fix a crash on tracking Objective-C 'self' as a control dependency.
Artem Dergachev via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 18 18:50:43 PDT 2019
Author: dergachev
Date: Fri Oct 18 18:50:43 2019
New Revision: 375328
URL: http://llvm.org/viewvc/llvm-project?rev=375328&view=rev
Log:
[analyzer] Fix a crash on tracking Objective-C 'self' as a control dependency.
'self' was previously never tracked, but now it can be tracked
because it may be part of a condition.
Added:
cfe/trunk/test/Analysis/track-control-dependency-conditions.m
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=375328&r1=375327&r2=375328&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Fri Oct 18 18:50:43 2019
@@ -1418,14 +1418,19 @@ FindLastStoreBRVisitor::VisitNode(const
if (Optional<CallEnter> CE = Succ->getLocationAs<CallEnter>()) {
if (const auto *VR = dyn_cast<VarRegion>(R)) {
- const auto *Param = cast<ParmVarDecl>(VR->getDecl());
+ if (const auto *Param = dyn_cast<ParmVarDecl>(VR->getDecl())) {
+ ProgramStateManager &StateMgr = BRC.getStateManager();
+ CallEventManager &CallMgr = StateMgr.getCallEventManager();
- ProgramStateManager &StateMgr = BRC.getStateManager();
- CallEventManager &CallMgr = StateMgr.getCallEventManager();
-
- CallEventRef<> Call = CallMgr.getCaller(CE->getCalleeContext(),
- Succ->getState());
- InitE = Call->getArgExpr(Param->getFunctionScopeIndex());
+ CallEventRef<> Call = CallMgr.getCaller(CE->getCalleeContext(),
+ Succ->getState());
+ InitE = Call->getArgExpr(Param->getFunctionScopeIndex());
+ } else {
+ // Handle Objective-C 'self'.
+ assert(isa<ImplicitParamDecl>(VR->getDecl()));
+ InitE = cast<ObjCMessageExpr>(CE->getCalleeContext()->getCallSite())
+ ->getInstanceReceiver()->IgnoreParenCasts();
+ }
IsParam = true;
}
}
Added: cfe/trunk/test/Analysis/track-control-dependency-conditions.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/track-control-dependency-conditions.m?rev=375328&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/track-control-dependency-conditions.m (added)
+++ cfe/trunk/test/Analysis/track-control-dependency-conditions.m Fri Oct 18 18:50:43 2019
@@ -0,0 +1,32 @@
+// RUN: %clang_analyze_cc1 -w -analyzer-checker=core,nullability -verify %s
+
+// expected-no-diagnostics
+
+ at class C;
+
+#pragma clang assume_nonnull begin
+ at interface I
+- foo:(C *)c;
+ at end
+#pragma clang assume_nonnull end
+
+ at interface J
+ at property C *c;
+ at end
+
+J *conjure_J();
+
+ at implementation I
+- (void)bar {
+ if (self) { // no-crash
+ J *j = conjure_J();
+ if (j.c)
+ [self bar];
+ // FIXME: Should warn.
+ [self foo:j.c]; // no-warning
+ }
+}
+ at end
+
+ at implementation J
+ at end
More information about the cfe-commits
mailing list