Skip to content

[cherry-pick][-Wcompletion-handler] Fix a non-termination issue (#78380) #8082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions clang/lib/Analysis/CalledOnceCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class ParameterStatus {
NotVisited = 0x8, /* 1000 */
// We already reported a violation and stopped tracking calls for this
// parameter.
Reported = 0x15, /* 1111 */
Reported = 0xF, /* 1111 */
LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue = */ Reported)
};

Expand Down Expand Up @@ -932,7 +932,8 @@ class CalledOnceChecker : public ConstStmtVisitor<CalledOnceChecker> {
ParameterStatus &CurrentParamStatus = CurrentState.getStatusFor(Index);

// Escape overrides whatever error we think happened.
if (CurrentParamStatus.isErrorStatus()) {
if (CurrentParamStatus.isErrorStatus() &&
CurrentParamStatus.getKind() != ParameterStatus::Kind::Reported) {
CurrentParamStatus = ParameterStatus::Escaped;
}
}
Expand Down
10 changes: 10 additions & 0 deletions clang/test/SemaObjC/warn-called-once.m
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,16 @@ - (void)test_escape_after_branch:(int)cond
}

// rdar://74441906
- (void)test_termination:(int)cond
withCompletion:(void (^)(void))handler {
// The code below was able to cause non-termination but should be
// fixed now:
do {
escape(handler);
handler(); // expected-warning{{completion handler is called twice}} expected-note{{previous call is here; set to nil to indicate it cannot be called afterwards}}
} while (cond);
}

typedef void (^DeferredBlock)(void);
static inline void DefferedCallback(DeferredBlock *inBlock) { (*inBlock)(); }
#define _DEFERCONCAT(a, b) a##b
Expand Down