[PATCH] D71694: [objc_direct] Tigthen checks for direct methods

Pierre Habouzit via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 19 02:02:32 PST 2019


MadCoder created this revision.
MadCoder added reviewers: rjmccall, dexonsmith, erik.pilkington, ahatanak, arphaman.
MadCoder added a project: clang.
Herald added a subscriber: cfe-commits.

Because the name of a direct method must be agreed upon by the caller and the implementation, certain bad practices that one can get away with when using dynamism are fatal with direct methods.

To avoid really weird and unscruttable linker error, tighten the front-end error reporting.

Rule 1:

  Direct methods can only have at most one declaration in an @interface container. Any redeclaration is strictly forbidden.
  Today some amount of redeclaration is tolerated between the main interface and categories for dynamic methods, but we can't have that.

Rule 2:

  Direct method implementations can only be declared in a matching @interface container: when implemented in the primary @implementation then the declaration must be in the primary @interface or an extension, and when implemented in a category, the declaration must be in the @interface for the same category.

Also fix another issue with ObjCMethod::getCanonicalDecl(): when an implementation lives in the primary @interface, then its canonical declaration can be in any extension, even when it's not an accessor.

Add Sema tests to cover the new errors, and CG tests to beef up testing around function names for categories and extensions.

Radar-Id: rdar://problem/58054563


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71694

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/DeclObjC.cpp
  clang/lib/Sema/SemaDeclObjC.cpp
  clang/test/CodeGenObjC/direct-method.m
  clang/test/SemaObjC/method-direct-one-definition.m

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71694.234680.patch
Type: text/x-patch
Size: 11935 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191219/5e92dbd1/attachment.bin>


More information about the cfe-commits mailing list