Skip to content

Commit d8cf20e

Browse files
committed
SIL: Fix oversight in switch_enum vs switch_enum_addr verification
Just like a switch_enum, switch_enum_addr must have a default case if the enum is resilient from the current function.
1 parent d0e92f8 commit d8cf20e

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

lib/SIL/SILVerifier.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3932,8 +3932,6 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
39323932

39333933
// Find the set of enum elements for the type so we can verify
39343934
// exhaustiveness.
3935-
// FIXME: We also need to consider if the enum is resilient, in which case
3936-
// we're never guaranteed to be exhaustive.
39373935
llvm::DenseSet<EnumElementDecl*> unswitchedElts;
39383936
uDecl->getAllElements(unswitchedElts);
39393937

@@ -4019,8 +4017,6 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
40194017

40204018
// Find the set of enum elements for the type so we can verify
40214019
// exhaustiveness.
4022-
// FIXME: We also need to consider if the enum is resilient, in which case
4023-
// we're never guaranteed to be exhaustive.
40244020
llvm::DenseSet<EnumElementDecl*> unswitchedElts;
40254021
uDecl->getAllElements(unswitchedElts);
40264022

@@ -4044,9 +4040,12 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
40444040
}
40454041

40464042
// If the switch is non-exhaustive, we require a default.
4047-
require(unswitchedElts.empty() || SOI->hasDefault(),
4048-
"nonexhaustive switch_enum_addr must have a default "
4049-
"destination");
4043+
bool isExhaustive =
4044+
uDecl->isEffectivelyExhaustive(F.getModule().getSwiftModule(),
4045+
F.getResilienceExpansion());
4046+
require((isExhaustive && unswitchedElts.empty()) || SOI->hasDefault(),
4047+
"nonexhaustive switch_enum_addr must have a default destination");
4048+
40504049
if (SOI->hasDefault())
40514050
require(SOI->getDefaultBB()->args_empty(),
40524051
"switch_enum_addr default destination must take "

0 commit comments

Comments
 (0)