Skip to content

Commit

Permalink
[dart2js] Fix inconsistent treatment of statement
Browse files Browse the repository at this point in the history
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 <sra@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
  • Loading branch information
rakudrama authored and Commit Queue committed Jan 7, 2025
1 parent 259bf24 commit 8cd13b2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/compiler/lib/src/ssa/codegen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -524,18 +524,18 @@ class SsaCodeGenerator implements HVisitor<void>, 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
Expand Down
7 changes: 7 additions & 0 deletions tests/web/regress/issue/59790_test.dart
Original file line number Diff line number Diff line change
@@ -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++) {}
}

0 comments on commit 8cd13b2

Please sign in to comment.