llvm-project/clang/lib/Sema
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
..
AnalysisBasedWarnings.cpp New tautological warning for bitwise-or with non-zero constant always true. 2019-10-19 00:57:23 +00:00
CMakeLists.txt [Concepts] Concept Specialization Expressions 2019-10-15 15:24:26 +00:00
CodeCompleteConsumer.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CoroutineStmtBuilder.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
DeclSpec.cpp [c++20] P1143R2: Add support for the C++20 'constinit' keyword. 2019-09-04 20:30:37 +00:00
DelayedDiagnostic.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
IdentifierResolver.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
JumpDiagnostics.cpp Revert "[NFC] Refactor representation of materialized temporaries" 2019-11-17 02:09:25 -05:00
MultiplexExternalSemaSource.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
OpenCLBuiltins.td [OpenCL] Add remaining vector data builtin functions 2019-11-13 10:16:33 +00:00
ParsedAttr.cpp Move some definitions from Sema to Basic to fix shared libs build 2019-09-16 13:58:59 +00:00
Scope.cpp Un-revert "[coroutines][PR40978] Emit error for co_yield within catch block" 2019-03-25 00:53:10 +00:00
ScopeInfo.cpp PR42104: Support instantiations of lambdas that implicitly capture 2019-06-04 17:17:20 +00:00
Sema.cpp [Sema] Emit diagnostics for uncorrected delayed typos at the end of TU 2019-10-09 10:00:05 +00:00
SemaAccess.cpp Sema - silence static analyzer getAs<> null dereference warnings. NFCI. 2019-10-07 14:25:46 +00:00
SemaAttr.cpp Added support for "#pragma clang section relro=<name>" 2019-10-15 18:31:10 +00:00
SemaCUDA.cpp [HIP] Add option -fgpu-allow-device-init 2019-10-22 16:06:20 -04:00
SemaCXXScopeSpec.cpp [Clang] Migrate llvm::make_unique to std::make_unique 2019-08-14 23:04:18 +00:00
SemaCast.cpp [Diagnostics] Improve some error messages related to bad use of dynamic_cast 2019-11-04 16:26:43 +01:00
SemaChecking.cpp Revert "[NFC] Refactor representation of materialized temporaries" 2019-11-17 02:09:25 -05:00
SemaCodeComplete.cpp [CodeComplete] Constructor overload candidates report as vector(int) instead of vector<string>(int) 2019-11-15 15:42:18 +01:00
SemaConcept.cpp Revert "[Concepts] Constraint Enforcement & Diagnostics" 2019-10-28 15:00:40 -07:00
SemaConsumer.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
SemaCoroutine.cpp Avoid including Builtins.h in Preprocessor.h 2019-11-15 16:45:16 -08:00
SemaDecl.cpp [Attr] Fix `-ast-print` for `asm` attribute 2019-11-18 11:55:25 -05:00
SemaDeclAttr.cpp Implement __attribute__((objc_direct)), __attribute__((objc_direct_members)) 2019-11-18 11:48:40 -08:00
SemaDeclCXX.cpp Revert "[Concepts] Constraint Enforcement & Diagnostics" 2019-10-28 15:00:40 -07:00
SemaDeclObjC.cpp Implement __attribute__((objc_direct)), __attribute__((objc_direct_members)) 2019-11-18 11:48:40 -08:00
SemaExceptionSpec.cpp SemaExceptionSpec - silence static analyzer getAs<> null dereference warnings. NFCI. 2019-10-21 18:28:31 +00:00
SemaExpr.cpp Revert "[NFC] Refactor representation of materialized temporaries" 2019-11-17 02:09:25 -05:00
SemaExprCXX.cpp [MS] Don't reference deleted copy ctors from catchable types 2019-10-30 15:06:26 -07:00
SemaExprMember.cpp Silence static analyzer getAs<RecordType> null dereference warnings. NFCI. 2019-10-03 11:22:48 +00:00
SemaExprObjC.cpp Implement __attribute__((objc_direct)), __attribute__((objc_direct_members)) 2019-11-18 11:48:40 -08:00
SemaFixItUtils.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
SemaInit.cpp Revert "[NFC] Refactor representation of materialized temporaries" 2019-11-17 02:09:25 -05:00
SemaLambda.cpp Minor coding style fix. NFC. 2019-10-22 04:32:30 +00:00
SemaLookup.cpp [Sema] Fixes a crash with a templated destructor 2019-11-07 21:22:27 +01:00
SemaModule.cpp Support for DWARF-5 C++ language tags. 2019-09-24 00:38:49 +00:00
SemaObjCProperty.cpp Implement __attribute__((objc_direct)), __attribute__((objc_direct_members)) 2019-11-18 11:48:40 -08:00
SemaOpenMP.cpp Fix "not all control paths return a value" warning. NFCI. 2019-11-18 11:42:14 +00:00
SemaOverload.cpp [NFC] Supress GCC "Bitfield too small to hold all values of enum" warning. 2019-11-09 05:56:51 -08:00
SemaPseudoObject.cpp [AST] Use an explicit copy in a range-based for 2019-11-12 20:47:46 +01:00
SemaStmt.cpp Revert "[NFC] Refactor representation of materialized temporaries" 2019-11-17 02:09:25 -05:00
SemaStmtAsm.cpp Delay diagnosing asm constraints that require immediates until after inlining 2019-08-06 22:41:22 +00:00
SemaStmtAttr.cpp [NFCI]Create CommonAttributeInfo Type as base type of *Attr and ParsedAttr. 2019-09-13 17:39:31 +00:00
SemaTemplate.cpp [Sema] Fixes templated friend member assertion 2019-11-05 21:46:42 +01:00
SemaTemplateDeduction.cpp Revert "[Concepts] Constraint Enforcement & Diagnostics" 2019-10-28 15:00:40 -07:00
SemaTemplateInstantiate.cpp Revert "[Concepts] Constraint Enforcement & Diagnostics" 2019-10-28 15:00:40 -07:00
SemaTemplateInstantiateDecl.cpp [OPENMP]Use copy constructors instead of assignment operators in declare 2019-11-12 13:13:37 -05:00
SemaTemplateVariadic.cpp PR42587: diagnose unexpanded uses of a pack parameter of a generic 2019-08-26 22:51:28 +00:00
SemaType.cpp [Sema] Add MacroQualified case for FunctionTypeUnwrapper 2019-11-12 16:22:13 -08:00
TreeTransform.h Revert "[NFC] Refactor representation of materialized temporaries" 2019-11-17 02:09:25 -05:00
TypeLocBuilder.cpp [NFC] avoid AlignedCharArray in clang 2019-07-29 23:12:48 +00:00
TypeLocBuilder.h [NFC] avoid AlignedCharArray in clang 2019-07-29 23:12:48 +00:00