llvm-project/clang/lib/Parse
Pierre Habouzit d4e1ba3fa9 Implement __attribute__((objc_direct)), __attribute__((objc_direct_members))
__attribute__((objc_direct)) is an attribute on methods declaration, and
__attribute__((objc_direct_members)) on implementation, categories or
extensions.

A `direct` property specifier is added (@property(direct) type name)

These attributes / specifiers cause the method to have no associated
Objective-C metadata (for the property or the method itself), and the
calling convention to be a direct C function call.

The symbol for the method has enforced hidden visibility and such direct
calls are hence unreachable cross image. An explicit C function must be
made if so desired to wrap them.

The implicit `self` and `_cmd` arguments are preserved, however to
maintain compatibility with the usual `objc_msgSend` semantics,
3 fundamental precautions are taken:

1) for instance methods, `self` is nil-checked. On arm64 backends this
   typically adds a single instruction (cbz x0, <closest-ret>) to the
   codegen, for the vast majority of the cases when the return type is a
   scalar.

2) for class methods, because the class may not be realized/initialized
   yet, a call to `[self self]` is emitted. When the proper deployment
   target is used, this is optimized to `objc_opt_self(self)`.

   However, long term we might want to emit something better that the
   optimizer can reason about. When inlining kicks in, these calls
   aren't optimized away as the optimizer has no idea that a single call
   is really necessary.

3) the calling convention for the `_cmd` argument is changed: the caller
   leaves the second argument to the call undefined, and the selector is
   loaded inside the body when it's referenced only.

As far as error reporting goes, the compiler refuses:
- making any overloads direct,
- making an overload of a direct method,
- implementations marked as direct when the declaration in the
  interface isn't (the other way around is allowed, as the direct
  attribute is inherited from the declaration),
- marking methods required for protocol conformance as direct,
- messaging an unqualified `id` with a direct method,
- forming any @selector() expression with only direct selectors.

As warnings:
- any inconsistency of direct-related calling convention when
  @selector() or messaging is used,
- forming any @selector() expression with a possibly direct selector.

Lastly an `objc_direct_members` attribute is added that can decorate
`@implementation` blocks and causes methods only declared there (and in
no `@interface`) to be automatically direct. When decorating an
`@interface` then all methods and properties declared in this block are
marked direct.

Radar-ID: rdar://problem/2684889
Differential Revision: https://reviews.llvm.org/D69991
Reviewed-By: John McCall
2019-11-18 11:48:40 -08:00
..
CMakeLists.txt
ParseAST.cpp Adds `-ftime-trace` option to clang that produces Chrome `chrome://tracing` compatible JSON profiling output dumps. 2019-03-30 08:42:48 +00:00
ParseCXXInlineMethods.cpp [Clang] Migrate llvm::make_unique to std::make_unique 2019-08-14 23:04:18 +00:00
ParseDecl.cpp [Parser] Warn when ScopeDepthOrObjCQuals overflows 2019-11-09 15:33:01 +01:00
ParseDeclCXX.cpp [clangd] Do not insert parentheses when completing a using declaration 2019-10-28 09:45:10 +01:00
ParseExpr.cpp [Concepts] Concept Specialization Expressions 2019-10-15 15:24:26 +00:00
ParseExprCXX.cpp [clangd] Do not insert parentheses when completing a using declaration 2019-10-28 09:45:10 +01:00
ParseInit.cpp [c++20] Add support for designated direct-list-initialization syntax. 2019-08-31 01:00:37 +00:00
ParseObjc.cpp Implement __attribute__((objc_direct)), __attribute__((objc_direct_members)) 2019-11-18 11:48:40 -08:00
ParseOpenMP.cpp [OpenMP 5.0] - Extend defaultmap, by Chi Chun Chen. 2019-11-15 13:53:32 -05:00
ParsePragma.cpp Added support for "#pragma clang section relro=<name>" 2019-10-15 18:31:10 +00:00
ParseStmt.cpp Include leading attributes in DeclStmt's SourceRange 2019-10-17 11:20:21 +00:00
ParseStmtAsm.cpp [Mips] Use appropriate private label prefix based on Mips ABI 2019-10-23 12:24:35 +02:00
ParseTemplate.cpp [clang] Make handling of unnamed template params similar to function params 2019-10-01 14:08:51 +00:00
ParseTentative.cpp PR43080: Do not build context-sensitive expressions during name classification. 2019-10-14 21:53:03 +00:00
Parser.cpp PR43080: Do not build context-sensitive expressions during name classification. 2019-10-14 21:53:03 +00:00