diff --git a/clang/lib/Analysis/CalledOnceCheck.cpp b/clang/lib/Analysis/CalledOnceCheck.cpp index 92d68d85fbc284..2438c50d7e4e6c 100644 --- a/clang/lib/Analysis/CalledOnceCheck.cpp +++ b/clang/lib/Analysis/CalledOnceCheck.cpp @@ -48,9 +48,12 @@ static constexpr unsigned EXPECTED_NUMBER_OF_BASIC_BLOCKS = 8; template using CFGSizedVector = llvm::SmallVector; constexpr llvm::StringLiteral CONVENTIONAL_NAMES[] = { - "completionHandler", "completion", "withCompletionHandler"}; + "completionHandler", "completion", "withCompletionHandler", + "withCompletion", "completionBlock", "withCompletionBlock", + "replyTo", "reply", "withReplyTo"}; constexpr llvm::StringLiteral CONVENTIONAL_SUFFIXES[] = { - "WithCompletionHandler", "WithCompletion"}; + "WithCompletionHandler", "WithCompletion", "WithCompletionBlock", + "WithReplyTo", "WithReply"}; constexpr llvm::StringLiteral CONVENTIONAL_CONDITIONS[] = { "error", "cancel", "shouldCall", "done", "OK", "success"}; @@ -994,13 +997,15 @@ class CalledOnceChecker : public ConstStmtVisitor { return hasConventionalSuffix(MethodSelector.getNameForSlot(0)); } - return isConventional(MethodSelector.getNameForSlot(PieceIndex)); + llvm::StringRef PieceName = MethodSelector.getNameForSlot(PieceIndex); + return isConventional(PieceName) || hasConventionalSuffix(PieceName); } bool shouldBeCalledOnce(const ParmVarDecl *Parameter) const { return isExplicitlyMarked(Parameter) || (CheckConventionalParameters && - isConventional(Parameter->getName()) && + (isConventional(Parameter->getName()) || + hasConventionalSuffix(Parameter->getName())) && isConventional(Parameter->getType())); } diff --git a/clang/test/SemaObjC/warn-called-once.m b/clang/test/SemaObjC/warn-called-once.m index 1014e173016386..3d846deca9211a 100644 --- a/clang/test/SemaObjC/warn-called-once.m +++ b/clang/test/SemaObjC/warn-called-once.m @@ -1036,6 +1036,20 @@ - (void)testWithCompletion:(void (^)(void))callback { } } +- (void)test:(int)cond fooWithReplyTo:(void (^)(void))handler { + if (cond) { + // expected-warning@-1{{completion handler is never called when taking false branch}} + handler(); + } +} + +- (void)test:(int)cond with:(void (^)(void))fooWithCompletionBlock { + if (cond) { + // expected-warning@-1{{completion handler is never called when taking false branch}} + fooWithCompletionBlock(); + } +} + - (void)completion_handler_wrong_type:(int (^)(void))completionHandler { // We don't want to consider completion handlers with non-void return types. if ([self condition]) {