mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 22:49:53 +00:00
[dart2wasm] Emit unreachable as default case when switch is exhaustive
The front-end variable initialization analysis considers a variable definitely initialized if it's initialized in all `case` branches of an "explicitly exhaustive" `switch` statement, i.e. a `switch` statement switching on an enum value where the `case` branches cover all variants of the enum. In order for the emitted Wasm code to validate according to the flow-sensitive non-nullable locals validation scheme being discussed in https://github.com/WebAssembly/function-references/issues/44 this definite initialization must be reflected in the static control flow of the Wasm code. Thus, such a switch statement must not have static control flow exiting the switch statement through the (dynamically unreachable) default case. Change-Id: I53628d2c6e9690214ffb4c60498c4f2b895f33e7 Cq-Include-Trybots: luci.dart.try:dart2wasm-linux-x64-d8-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/245985 Reviewed-by: Ömer Ağacan <omersa@google.com> Commit-Queue: Aske Simon Christensen <askesc@google.com>
This commit is contained in:
parent
608b95c9b4
commit
79abd5ea56
|
@ -990,9 +990,15 @@ class CodeGenerator extends ExpressionVisitor1<w.ValueType, w.ValueType>
|
|||
}
|
||||
}
|
||||
}
|
||||
w.Label defaultLabel =
|
||||
defaultCase != null ? switchLabels[defaultCase]! : doneLabel;
|
||||
b.br(defaultLabel);
|
||||
|
||||
// No explicit cases matched
|
||||
if (node.isExplicitlyExhaustive) {
|
||||
b.unreachable();
|
||||
} else {
|
||||
w.Label defaultLabel =
|
||||
defaultCase != null ? switchLabels[defaultCase]! : doneLabel;
|
||||
b.br(defaultLabel);
|
||||
}
|
||||
|
||||
// Emit case bodies
|
||||
for (SwitchCase c in node.cases) {
|
||||
|
|
Loading…
Reference in a new issue