Commit Graph

4 Commits

Author SHA1 Message Date
Erik Eckstein
a768037d0b IRGen: fix failing unconditional class casts
When unconditionally casting from a base to a final derived class, e.g. `base as! Derived`, the program did not abort with a trap.
Instead the resulting null-pointer caused a crash later in the program.
This fix inserts a trap condition for the failing case of such a cast.

rdar://151462303
2025-05-19 16:56:47 +02:00
Erik Eckstein
2527d3765e IRGen: fix how metadata is loaded for fast class casting
Pass the correct type to `emitHeapMetadataRefForHeapObject()`.
Fixes a runtime crash in case a class protocol is cast to a final swift class, where the actual object is an ObjectiveC class instance.

rdar://99626888
2022-09-22 08:46:18 +02:00
Slava Pestov
c80d8e6b1c IRGen: Exclude classes defined in generic contexts from fast cast optimization
This is a regression from https://github.com/apple/swift/pull/41784.

Fixes rdar://problem/93822961.
2022-07-12 04:11:32 -04:00
Erik Eckstein
860078a79a IRGen: fast casting to final classes
When casting a class instance to a final class, we can directly compare the isa-pointer with address of the metadata.
This avoids a call to `swift_dynamicCastClass`.
It also avoids a call to the metadata accessor of the class (which calls `swift_getInitializedObjCClass`).
For comparing the metadata pointers it's not required that the metadata is fully initialized.
2022-04-07 16:36:21 +02:00