]> granicus.if.org Git - clang/commit
Add the `objc_class_stub` attribute.
authorJohn McCall <rjmccall@apple.com>
Thu, 30 May 2019 04:09:01 +0000 (04:09 +0000)
committerJohn McCall <rjmccall@apple.com>
Thu, 30 May 2019 04:09:01 +0000 (04:09 +0000)
commit64add31d1a424e433ac347d0d4a019b6572d6c99
tree962404613f92aa51726a385c88981c129c1653e7
parenta59c51ceaf36b891acc3a98fa12e67819d7993df
Add the `objc_class_stub` attribute.

Swift requires certain classes to be not just initialized lazily on first
use, but actually allocated lazily using information that is only available
at runtime.  This is incompatible with ObjC class initialization, or at least
not efficiently compatible, because there is no meaningful class symbol
that can be put in a class-ref variable at load time.  This leaves ObjC
code unable to access such classes, which is undesirable.

objc_class_stub says that class references should be resolved by calling
a new ObjC runtime function with a pointer to a new "class stub" structure.
Non-ObjC compilers (like Swift) can simply emit this structure when ObjC
interop is required for a class that cannot be statically allocated,
then apply this attribute to the `@interface` in the generated ObjC header
for the class.

This attribute can be thought of as a generalization of the existing
`objc_runtime_visible` attribute which permits more efficient class
resolution as well as supporting the additon of categories to the class.
Subclassing these classes from ObjC is currently not allowed.

Patch by Slava Pestov!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@362054 91177308-0d34-0410-b5e6-96231b3b80d8
12 files changed:
include/clang/Basic/Attr.td
include/clang/Basic/AttrDocs.td
include/clang/Basic/DiagnosticSemaKinds.td
include/clang/Basic/ObjCRuntime.h
lib/CodeGen/CGObjCMac.cpp
lib/Sema/SemaDeclAttr.cpp
lib/Sema/SemaDeclObjC.cpp
test/CodeGenObjC/class-stubs.m [new file with mode: 0644]
test/Misc/pragma-attribute-supported-attributes-list.test
test/SemaObjC/class-stub-attr-unsupported.m [new file with mode: 0644]
test/SemaObjC/class-stub-attr.m [new file with mode: 0644]
utils/TableGen/ClangAttrEmitter.cpp