@@ -867,16 +867,14 @@ class CalledOnceChecker : public ConstStmtVisitor<CalledOnceChecker> {
867
867
// Let's check if any of the call arguments is a point of interest.
868
868
for (const auto &Argument : llvm::enumerate (Arguments)) {
869
869
if (auto Index = getIndexOfExpression (Argument.value ())) {
870
- ParameterStatus &CurrentParamStatus = CurrentState.getStatusFor (*Index);
871
-
872
870
if (shouldBeCalledOnce (CallOrMessage, Argument.index ())) {
873
871
// If the corresponding parameter is marked as 'called_once' we should
874
872
// consider it as a call.
875
873
processCallFor (*Index, CallOrMessage);
876
- } else if (CurrentParamStatus. getKind () == ParameterStatus::NotCalled) {
874
+ } else {
877
875
// Otherwise, we mark this parameter as escaped, which can be
878
876
// interpreted both as called or not called depending on the context.
879
- CurrentParamStatus = ParameterStatus::Escaped ;
877
+ processEscapeFor (*Index) ;
880
878
}
881
879
// Otherwise, let's keep the state as it is.
882
880
}
@@ -910,6 +908,16 @@ class CalledOnceChecker : public ConstStmtVisitor<CalledOnceChecker> {
910
908
}
911
909
}
912
910
911
+ // / Process escape of the parameter with the given index
912
+ void processEscapeFor (unsigned Index) {
913
+ ParameterStatus &CurrentParamStatus = CurrentState.getStatusFor (Index);
914
+
915
+ // Escape overrides whatever error we think happened.
916
+ if (CurrentParamStatus.isErrorStatus ()) {
917
+ CurrentParamStatus = ParameterStatus::Escaped;
918
+ }
919
+ }
920
+
913
921
void findAndReportNotCalledBranches (const CFGBlock *Parent, unsigned Index,
914
922
bool IsEscape = false ) {
915
923
for (const CFGBlock *Succ : Parent->succs ()) {
@@ -1365,11 +1373,7 @@ class CalledOnceChecker : public ConstStmtVisitor<CalledOnceChecker> {
1365
1373
// / Check given parameter that was discovered to escape.
1366
1374
void checkEscapee (const ParmVarDecl &Parameter) {
1367
1375
if (auto Index = getIndex (Parameter)) {
1368
- ParameterStatus &CurrentParamStatus = CurrentState.getStatusFor (*Index);
1369
-
1370
- if (CurrentParamStatus.getKind () == ParameterStatus::NotCalled) {
1371
- CurrentParamStatus = ParameterStatus::Escaped;
1372
- }
1376
+ processEscapeFor (*Index);
1373
1377
}
1374
1378
}
1375
1379
0 commit comments