Skip to content

Commit f208e4a

Browse files
committed
SILVerifier: Fix crashes when verifying type dependent arguments.
`getRootLocalArchetypeDef()` may return a `PlaceholderValue` which makes the `cast<SingleValueInstruction>` invalid. Use `dyn_cast` and then update the callers of `getRootLocalArchetypeDefInst()` to handle `nullptr`.
1 parent 98e65d0 commit f208e4a

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

include/swift/SIL/SILModule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ class SILModule {
473473
SingleValueInstruction *
474474
getRootLocalArchetypeDefInst(CanLocalArchetypeType archetype,
475475
SILFunction *inFunction) {
476-
return cast<SingleValueInstruction>(
476+
return dyn_cast<SingleValueInstruction>(
477477
getRootLocalArchetypeDef(archetype, inFunction));
478478
}
479479

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,6 +1703,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
17031703
// the current function.
17041704
auto *openingInst = F.getModule().getRootLocalArchetypeDefInst(
17051705
root, AI->getFunction());
1706+
require(openingInst,
1707+
"Root opened archetype should be registered in SILModule");
17061708
require(openingInst == AI || properlyDominates(openingInst, AI),
17071709
"Use of a local archetype should be dominated by a "
17081710
"definition of this root opened archetype");

0 commit comments

Comments
 (0)