[PATCH] D98251: [-Wcompletion-handler] Extend list of detected conventions
Valeriy Savchenko via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 9 23:43:52 PST 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG59112eacb979: [-Wcompletion-handler] Extend list of detected conventions (authored by vsavchenko).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D98251/new/
https://reviews.llvm.org/D98251
Files:
clang/lib/Analysis/CalledOnceCheck.cpp
clang/test/SemaObjC/warn-called-once.m
Index: clang/test/SemaObjC/warn-called-once.m
===================================================================
--- clang/test/SemaObjC/warn-called-once.m
+++ clang/test/SemaObjC/warn-called-once.m
@@ -1036,6 +1036,20 @@
}
}
+- (void)test:(int)cond fooWithReplyTo:(void (^)(void))handler {
+ if (cond) {
+ // expected-warning at -1{{completion handler is never called when taking false branch}}
+ handler();
+ }
+}
+
+- (void)test:(int)cond with:(void (^)(void))fooWithCompletionBlock {
+ if (cond) {
+ // expected-warning at -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]) {
Index: clang/lib/Analysis/CalledOnceCheck.cpp
===================================================================
--- clang/lib/Analysis/CalledOnceCheck.cpp
+++ clang/lib/Analysis/CalledOnceCheck.cpp
@@ -48,9 +48,12 @@
template <class T>
using CFGSizedVector = llvm::SmallVector<T, EXPECTED_NUMBER_OF_BASIC_BLOCKS>;
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 @@
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()));
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98251.329548.patch
Type: text/x-patch
Size: 2520 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210310/8bce37e1/attachment.bin>
More information about the cfe-commits
mailing list