Skip to content

Commit c1a0c61

Browse files
aartbikcommit-bot@chromium.org
authored andcommitted
[vm/compiler] Add missing case for CP
Rationale: Constant propagator was missing a case for a double binary operator. dart-lang#35321 dart-lang#35355 Change-Id: Ie88fe082e88b74651e798d516784737b36b4dcd1 Reviewed-on: https://dart-review.googlesource.com/c/86101 Reviewed-by: Ryan Macnak <[email protected]> Commit-Queue: Aart Bik <[email protected]>
1 parent b18de84 commit c1a0c61

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

runtime/vm/compiler/backend/constant_propagator.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,9 @@ void ConstantPropagator::VisitBinaryDoubleOp(BinaryDoubleOpInstr* instr) {
11601160
}
11611161
const Double& result = Double::ZoneHandle(Double::NewCanonical(result_val));
11621162
SetValue(instr, result);
1163+
} else if (IsConstant(left) && IsConstant(right)) {
1164+
// Both values known, but no rule to evaluate this further.
1165+
SetValue(instr, non_constant_);
11631166
}
11641167
}
11651168

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// Proper CP on double op (dartbug.com/35321).
6+
//
7+
// VMOptions=--deterministic --optimization_counter_threshold=10
8+
9+
import "package:expect/expect.dart";
10+
11+
double foo(bool x) {
12+
if (x) return 1.0;
13+
}
14+
15+
int bar(int i) {
16+
if (i < 0) {
17+
return bar(i + 1);
18+
} else if ((foo(i == 22) / 22.0) >= (1 / 0.0)) {
19+
return 1;
20+
}
21+
return 0;
22+
}
23+
24+
void main() {
25+
for (int i = 0; i < 20; ++i) {
26+
var x = -1;
27+
try {
28+
x = bar(i);
29+
} catch (_) {
30+
x = -2;
31+
}
32+
Expect.equals(-2, x);
33+
}
34+
}

0 commit comments

Comments
 (0)