mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[cast-optimizer] Fix incorrect handling of returned pointers.
Put simply, the method Type::getAnyNominal() returns either a nominal type or a nullptr. We are then casting it using dyn_cast to a ProtocolDecl. dyn_cast is not allowed to handle nullptrs... hence the crash. The fix is to use the API dyn_cast_or_null, the specific cast meant for this case! In terms of how this effects the flow of the code in such a case, we will just bail early if we have a non-nominal type today (which to me means at least metatypes, which is this case). I included a test case that we crash on without my change today and just do not optimize. rdar://87989767
This commit is contained in:
@@ -1547,7 +1547,7 @@ static bool optimizeStaticallyKnownProtocolConformance(
|
||||
auto &Ctx = Mod.getASTContext();
|
||||
auto *SM = Mod.getSwiftModule();
|
||||
|
||||
auto Proto = dyn_cast<ProtocolDecl>(TargetType->getAnyNominal());
|
||||
auto *Proto = dyn_cast_or_null<ProtocolDecl>(TargetType->getAnyNominal());
|
||||
if (!Proto)
|
||||
return false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user