Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(315)

Unified Diff: sdk/lib/_internal/compiler/implementation/ssa/codegen.dart

Issue 190763013: Detect total switches to prevent type pollution by default cases. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/compiler/implementation/ssa/codegen.dart
diff --git a/sdk/lib/_internal/compiler/implementation/ssa/codegen.dart b/sdk/lib/_internal/compiler/implementation/ssa/codegen.dart
index 4f14f5064533f0250cdcdaea653d49c14863a715..38d324b62053d61a3ea9576be8f056b23e772564 100644
--- a/sdk/lib/_internal/compiler/implementation/ssa/codegen.dart
+++ b/sdk/lib/_internal/compiler/implementation/ssa/codegen.dart
@@ -656,20 +656,36 @@ class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor {
inputIndex < inputs.length;
statementIndex++) {
HBasicBlock successor = successors[inputIndex - 1];
- do {
- visit(inputs[inputIndex]);
- currentContainer = new js.Block.empty();
- cases.add(new js.Case(pop(), currentContainer));
- inputIndex++;
- } while ((successors[inputIndex - 1] == successor)
- && (inputIndex < inputs.length));
-
- generateStatements(info.statements[statementIndex]);
+ // If liveness analysis has figured out that this case is dead,
+ // omit the code for it.
+ if (successor.isLive) {
+ do {
+ visit(inputs[inputIndex]);
+ currentContainer = new js.Block.empty();
+ cases.add(new js.Case(pop(), currentContainer));
+ inputIndex++;
+ } while ((successors[inputIndex - 1] == successor)
+ && (inputIndex < inputs.length));
+
+ generateStatements(info.statements[statementIndex]);
+ } else {
+ // Skip all the case statements that belong to this
+ // block.
+ while ((successors[inputIndex - 1] == successor)
+ && (inputIndex < inputs.length)) {
+ ++inputIndex;
+ }
+ }
}
- currentContainer = new js.Block.empty();
- cases.add(new js.Default(currentContainer));
- generateStatements(info.statements.last);
+ // If the default case is dead, we omit it. Likewise, if it is an
+ // empty block, we omit it, too.
+ if (info.statements.last.start.isLive) {
+ currentContainer = new js.Block.empty();
+ generateStatements(info.statements.last);
karlklose 2014/03/12 14:43:45 Why did you change the order here?
herhut 2014/03/13 13:27:45 I need to generate the statements to see whether t
+ if (currentContainer.statements.isNotEmpty)
karlklose 2014/03/12 14:43:45 Please use curly braces.
herhut 2014/03/13 13:27:45 Done.
+ cases.add(new js.Default(currentContainer));
+ }
currentContainer = oldContainer;

Powered by Google App Engine
This is Rietveld 408576698