[PATCH] D99601: [-Wcompletion-handler] Don't recognize init methods as conventional

Valeriy Savchenko via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 7 03:50:30 PDT 2021


This revision was automatically updated to reflect the committed changes.
vsavchenko marked an inline comment as done.
Closed by commit rG77f1e096e8a0: [-Wcompletion-handler] Don't recognize init methods as conventional (authored by vsavchenko).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99601/new/

https://reviews.llvm.org/D99601

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
@@ -13,6 +13,7 @@
 @protocol NSObject
 @end
 @interface NSObject <NSObject>
+- (instancetype)init;
 - (id)copy;
 - (id)class;
 - autorelease;
@@ -1235,4 +1236,13 @@
   handler(); // expected-warning{{completion handler is called twice}}
 }
 
+- (void)initWithAdditions:(int)cond
+           withCompletion:(void (^)(void))handler {
+  self = [self init];
+  if (self) {
+    escape(handler);
+  }
+  // no-warning
+}
+
 @end
Index: clang/lib/Analysis/CalledOnceCheck.cpp
===================================================================
--- clang/lib/Analysis/CalledOnceCheck.cpp
+++ clang/lib/Analysis/CalledOnceCheck.cpp
@@ -1011,11 +1011,16 @@
     return llvm::None;
   }
 
+  /// Return true if the specified selector represents init method.
+  static bool isInitMethod(Selector MethodSelector) {
+    return MethodSelector.getMethodFamily() == OMF_init;
+  }
+
   /// Return true if the specified selector piece matches conventions.
   static bool isConventionalSelectorPiece(Selector MethodSelector,
                                           unsigned PieceIndex,
                                           QualType PieceType) {
-    if (!isConventional(PieceType)) {
+    if (!isConventional(PieceType) || isInitMethod(MethodSelector)) {
       return false;
     }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99601.335776.patch
Type: text/x-patch
Size: 1478 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210407/766fb800/attachment-0001.bin>


More information about the cfe-commits mailing list