Skip to content

Commit 5a2df1c

Browse files
authored
Merge pull request #41034 from gottesmm/release/5.6/rdar87989767
[5.6][cast-optimizer] Fix incorrect handling of returned pointers.
2 parents 6e74363 + 4ba7f8d commit 5a2df1c

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/SILOptimizer/Utils/CastOptimizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1547,7 +1547,7 @@ static bool optimizeStaticallyKnownProtocolConformance(
15471547
auto &Ctx = Mod.getASTContext();
15481548
auto *SM = Mod.getSwiftModule();
15491549

1550-
auto Proto = dyn_cast<ProtocolDecl>(TargetType->getAnyNominal());
1550+
auto *Proto = dyn_cast_or_null<ProtocolDecl>(TargetType->getAnyNominal());
15511551
if (!Proto)
15521552
return false;
15531553

test/SILOptimizer/sil_combine_casts.sil

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,3 +332,25 @@ bb0(%0 : $*T, %1 : $Builtin.RawPointer, %2 : $@thick T.Type):
332332
%15 = tuple ()
333333
return %15 : $()
334334
}
335+
336+
public protocol AnyAction {
337+
}
338+
339+
public struct MyAction : AnyAction {
340+
}
341+
342+
// Make sure that we do not crash on this test case!
343+
//
344+
// TODO: Maybe we could handle this?
345+
sil shared @cast_optimizer_metatype_crasher : $@convention(thin) (@thick MyAction.Type) -> @thick AnyAction.Type {
346+
bb0(%0 : $@thick MyAction.Type):
347+
%1 = alloc_stack $@thick AnyAction.Type
348+
%2 = alloc_stack $@thick MyAction.Type
349+
store %0 to %2 : $*@thick MyAction.Type
350+
unconditional_checked_cast_addr MyAction.Type in %2 : $*@thick MyAction.Type to AnyAction.Type in %1 : $*@thick AnyAction.Type
351+
dealloc_stack %2 : $*@thick MyAction.Type
352+
%6 = tuple ()
353+
%7 = load %1 : $*@thick AnyAction.Type
354+
dealloc_stack %1 : $*@thick AnyAction.Type
355+
return %7 : $@thick AnyAction.Type
356+
}

0 commit comments

Comments
 (0)