[all-commits] [llvm/llvm-project] 42f9d0: [objc_direct] Tigthen checks for direct methods

Pierre Habouzit via All-commits all-commits at lists.llvm.org
Fri Dec 20 10:57:42 PST 2019


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 42f9d0c0bee32a1a48a45c039988d27115f30da9
      https://github.com/llvm/llvm-project/commit/42f9d0c0bee32a1a48a45c039988d27115f30da9
  Author: Pierre Habouzit <phabouzit at apple.com>
  Date:   2019-12-20 (Fri, 20 Dec 2019)

  Changed paths:
    M clang/include/clang/Basic/DiagnosticSemaKinds.td
    M clang/lib/AST/DeclObjC.cpp
    M clang/lib/CodeGen/CGObjCMac.cpp
    M clang/lib/Sema/SemaDeclObjC.cpp
    M clang/test/CodeGenObjC/direct-method.m
    A clang/test/SemaObjC/method-direct-one-definition.m

  Log Message:
  -----------
  [objc_direct] Tigthen checks for direct methods

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>

Differential Revision: https://reviews.llvm.org/D71694




More information about the All-commits mailing list