From 8cd13b290ced762280b8f06df4a999b87529f1e8 Mon Sep 17 00:00:00 2001 From: Stephen Adams Date: Mon, 6 Jan 2025 17:56:00 -0800 Subject: [PATCH] [dart2js] Fix inconsistent treatment of statement HArrayFlagsSet is compiled to a JavaScript statement, but the codegen predicate testing for when a condition subgraph can be compiled to an expression accepts HArrayFlagsSet because it tests for an instruction that has control flow (mostly jumps and checks). Test for `isJsStatement()` instead. Bug: #59790 Change-Id: Iafc21aa25490cb93503bb2be1f11dec2f71b5054 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403204 Commit-Queue: Stephen Adams Reviewed-by: Mayank Patke --- pkg/compiler/lib/src/ssa/codegen.dart | 12 ++++++------ tests/web/regress/issue/59790_test.dart | 7 +++++++ 2 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 tests/web/regress/issue/59790_test.dart diff --git a/pkg/compiler/lib/src/ssa/codegen.dart b/pkg/compiler/lib/src/ssa/codegen.dart index cca8c04daf25..6ea5f668fe3a 100644 --- a/pkg/compiler/lib/src/ssa/codegen.dart +++ b/pkg/compiler/lib/src/ssa/codegen.dart @@ -524,18 +524,18 @@ class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor { HSubExpressionBlockInformation expressionInfo = info; SubGraph limits = expressionInfo.subExpression!; - // Start assuming that we can generate declarations. If we find a - // counter-example, we degrade our assumption to either expression or - // statement, and in the latter case, we can return immediately since - // it can't get any worse. E.g., a function call where the return value - // isn't used can't be in a declaration. + // Start assuming that we can generate declarations for simple local + // variables. If we find a counter-example, we degrade our assumption to + // either expression or statement, and in the latter case, we can return + // immediately since it can't get any worse. E.g., a function call where the + // return value isn't used can't be in a declaration. var result = _ExpressionCodegenType.declaration; HBasicBlock basicBlock = limits.start; do { HInstruction current = basicBlock.first!; while (current != basicBlock.last) { // E.g, bounds check. - if (current.isControlFlow()) { + if (current.isJsStatement()) { return _ExpressionCodegenType.statement; } // HFieldSet generates code on the form "x.y = ...", which isn't valid diff --git a/tests/web/regress/issue/59790_test.dart b/tests/web/regress/issue/59790_test.dart new file mode 100644 index 000000000000..ccfbe744ede0 --- /dev/null +++ b/tests/web/regress/issue/59790_test.dart @@ -0,0 +1,7 @@ +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +void main() { + for (int i = 0; i < List.unmodifiable([]).length; i++) {} +}