Commit Graph

20 Commits

Author SHA1 Message Date
Erik Eckstein
7fe2befd31 Demangler: handle errors in demangleType
Makes sure that invalid runtime type strings result in errors and not fail silently.
In worst case this could lead to wrong reconstructed metatypes which can result in all kind of memory corruption.

relates to rdar://129861211
2024-07-05 11:37:15 +02:00
Doug Gregor
b5f45f8f72 [IRGen] Mangle Swift @objc(renamed) protocols as Objective-C in metadata.
When emitting metadata for a Swift-defined @objc protocol that has
provided a specific Objective-C name (e.g., via @objc(renamed)),
mangle such protocols using their Objective-C names so they can be
found at runtime.

Only do this for metadata, because doing it anywhere else would cause
an ABI break. Fixes rdar://problem/47877748.
2019-02-25 17:31:08 -08:00
Doug Gregor
c999ad0947 [Runtime] Correctly match demangle tree for generic Objective-C classes.
When we encounter the demangle tree for a bound generic class type, look
through the "Type" node of the child tree before checking whether we
have an Objective-C class name. If we do have an Objective-C class name,
there is no way to preserve the generic arguments, so we ignore them and
return the (non-generic) class type.

Fixes rdar://problem/47028102.
2019-01-03 11:12:13 -08:00
Doug Gregor
f223d0b886 [Runtime] Eliminate a use-after-free when comparing @objc type names.
We were creating a local Demangler instance, demangling a type name
using it, and then returning one of the resulting nodes to the caller.

Fixes rdar://problem/46817009.
2018-12-20 20:28:23 -08:00
Doug Gregor
a53b2e285c [Standard library] Drop _typeByMangledName().
This underscored function was only intended for testing; drop it from the
ABI. We’re keeping _typeByName because it’s used by Foundation.
2018-11-15 11:06:52 -08:00
Doug Gregor
9dd6a5f033 [Runtime] Use the old remangler to compute the @objc protocol name.
The “old” mangling that is used for runtime names of @objc protocols
uses a simpler substitution scheme, so you can’t simply take a mangled
name from the new mangling and fix up the ends.

Fixes rdar://problem/45685649.
2018-11-06 15:16:33 -08:00
Doug Gregor
452e1b12e1 [Runtime] Check for @objc existentials conforming to @objc protocols.
When checking conformance requirements against an @objc protocol, also
check for an @objc existential using protocol_conformsToProtocol().
Fixes rdar://problem/45685649.
2018-11-01 06:37:39 -07:00
Doug Gregor
c5e226bb16 [Runtime] Use CF superclass metadata in runtime lookups.
When searching the superclasses at runtime, e.g., to find a suitable
protocol conformance record, also consider the superclasses of CF
types, which were recorded in the metadata but otherwise unused.
2018-10-16 21:42:02 -07:00
Slava Pestov
0b0d7dcff9 Sema: Remove most of the remaining Swift 3 support 2018-10-08 18:43:52 -07:00
Doug Gregor
3dda40b17e [Runtime] Match up extensions of Objective-C classes by mangled nodes.
When comparing an extension context for Objective-C classes, there are no
context descriptors to use. Instead, perform a string match.
2018-09-25 10:53:54 -07:00
Joe Groff
e2dd2ff11f Runtime: Handle synthesized decl "related entity" tags.
Clang-importer-synthesized declarations get an extra tag character included in their mangling, which was not being preserved in type context descriptors. This caused runtime lookup for these synthesized types to fail. Fix this by adding the tag information to type context descriptors and teaching the runtime to match it up when fetching metadata by mangled name. Fixes rdar://problem/40878715.
2018-06-28 12:11:12 -07:00
Slava Pestov
5d2752f7d2 Run tests with -swift-version 4 by default
Some test now fail, so add an explicit -swift-version 3.
2018-06-19 23:24:19 -07:00
Doug Gregor
800e3818b7 [Type metadata] @objc protocol conformance requirements don't have arguments.
@objc protocols don't have witness tables. However, both type metadata
(in the nominal type descriptors) and the runtime code to demangle
type names into metadata weren't acknowledging this. Fix type metadata
emission to not count an "extra argument" for @objc protocol
conformance requirements, and teach the runtime code to properly look
for conformances to @objc protocols (through the Objective-C runtime)
and not record witness tables for them.
2018-02-15 14:07:46 -08:00
Doug Gregor
902ea27a67 [IRGen] Consistently record runtime metadata for foreign types.
All Swift-defined nominal types have their runtime metadata recorded
in a special section, so it can be found later. This recording is
suppressed when that type is stated to conform to a protocol, because
the runtime can find nominal types in either place.

Imported types would get their conformances recorded, but would not
get recorded in the runtime metadata record otherwose. Therefore, the
runtime would not be able to find such types by name.

For any foreign type whose metadata we emit, make sure that metadata
can be found by a runtime lookup.
2018-01-20 22:06:33 -08:00
Doug Gregor
2c9ad900ae [Mangled name -> metadata] Handle import-as-member types.
When import-as-member takes a C type and imports it as a nested type,
we end up with a nominal type descriptor for a nested type, but the
mangled name remains "flat". Cope with inconsistency to allow
_typeByMangledName() to handle such nested types.
2018-01-19 23:32:51 -08:00
Doug Gregor
817c0b368e [WIP] Emit nominal type access functions for imported types.
Emit nominal type access functions for imported types. These access
functions work with non-unique metadata references, so they perform
uniquing through the runtime on first access.

Fixes rdar://problem/36430234.
2018-01-19 23:11:50 -08:00
Doug Gregor
759f4c3a2c [Runtime] Skip Objective-C type records when looking for types.
When we scan the type metadata records or conformances to look
for a type by name, skip over indirect Objective-C class
references. We won’t find anything new there, but we’ll 
currently crash if they exist.
2018-01-11 00:14:41 -08:00
Doug Gregor
efde1dfc35 [Runtime] Support lookup of Objective-C classes.
Classes defined in Objective-C are mangled differently from
Swift-defined classes, and have no nominal type
descriptor. Recognize this mangling and search for the
appropriate Objective-C class using the Objective-C
runtime. Thread the resulting metadata through the mangled name
-> metadata decoder.
2018-01-10 16:56:51 -08:00
Doug Gregor
9916fdf17e [Runtime] Support lookup of Objective-C protocols.
Protocols defined in Objective-C are mangled differently from
Swift-defined protocols. Recognize this mangling and search for the
appropriate Objective-C protocol using the Objective-C runtime.
2018-01-10 16:46:12 -08:00
Doug Gregor
c302042dc5 [Runtime] Lookup @objc protocols in mangled name -> type metadata function.
Swift-defined @objc protocols are registered with the Objective-C runtime
under the Swift 3 mangling scheme; look in the Objective-C runting using
objc_getProtocol() with the appropriate name.

Also, correctly compute the "class bound" bit when forming a protocol
composition metatype. The information isn't in the mangled name when it
can be recovered from the protocols themselves, so look at the protocols.
2018-01-10 16:21:42 -08:00