-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[vm/compiler] Fix computation of ParameterInstr type in a catch block
In order to compute type, ParameterInstr::ComputeType() uses environment index to get a LocalVariable from LocalScope, assuming that environment index matches a variable index in the scope. This is only true for direct parameters (which are not copied in prologue). This change limits use of LocalVariable type for ParameterInstr corresponding to direct parameters. Note that it only affects Parameter instructions used in catch block entries, as ParameterInstr in function entry always corresponds to a direct parameter. TEST=runtime/tests/vm/dart/regress_flutter110715_il_test.dart Fixes flutter/flutter#110715 Change-Id: I68d423860928d7e65143844522e3006d9ccfcf66 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/257441 Commit-Queue: Alexander Markov <[email protected]> Reviewed-by: Slava Egorov <[email protected]>
- Loading branch information
1 parent
eb54019
commit f38a280
Showing
9 changed files
with
203 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Copyright (c) 2022, 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. | ||
|
||
// Regression test for https://github.com/flutter/flutter/issues/110715. | ||
// Verifies that compiler doesn't elide null check for a parameter in | ||
// a catch block in async/async* methods. | ||
|
||
import 'dart:async'; | ||
import 'package:vm/testing/il_matchers.dart'; | ||
|
||
@pragma('vm:never-inline') | ||
@pragma('vm:testing:print-flow-graph') | ||
Stream<Object> bug1(void Function()? f, void Function() g) async* { | ||
try { | ||
g(); | ||
throw 'error'; | ||
} catch (e) { | ||
// Should not crash when 'f' is null. | ||
f?.call(); | ||
} | ||
} | ||
|
||
@pragma('vm:never-inline') | ||
@pragma('vm:testing:print-flow-graph') | ||
Future<Object> bug2(void Function()? f, void Function() g) async { | ||
try { | ||
g(); | ||
throw 'error'; | ||
} catch (e) { | ||
// Should not crash when 'f' is null. | ||
f?.call(); | ||
} | ||
return ''; | ||
} | ||
|
||
void main() async { | ||
print(await bug1(null, () {}).toList()); | ||
print(await bug1(() {}, () {}).toList()); | ||
print(await bug2(null, () {})); | ||
print(await bug2(() {}, () {})); | ||
} | ||
|
||
void matchIL$bug1(FlowGraph graph) { | ||
graph.dump(); | ||
graph.match([ | ||
match.block('Graph'), | ||
match.block('Function'), | ||
match.block('Join'), | ||
match.block('CatchBlock', [ | ||
'v0' << match.Parameter(), | ||
match.Branch(match.StrictCompare('v0', match.any, kind: '==='), | ||
ifTrue: 'B6', ifFalse: 'B7'), | ||
]), | ||
'B6' << | ||
match.block('Target', [ | ||
match.Goto('B4'), | ||
]), | ||
'B7' << | ||
match.block('Target', [ | ||
match.ClosureCall(), | ||
match.Goto('B4'), | ||
]), | ||
'B4' << | ||
match.block('Join', [ | ||
match.Return(), | ||
]), | ||
]); | ||
} | ||
|
||
void matchIL$bug2(FlowGraph graph) { | ||
graph.dump(); | ||
graph.match([ | ||
match.block('Graph'), | ||
match.block('Function'), | ||
match.block('Join'), | ||
match.block('CatchBlock', [ | ||
'v0' << match.Parameter(), | ||
match.Branch(match.StrictCompare('v0', match.any, kind: '==='), | ||
ifTrue: 'B6', ifFalse: 'B7'), | ||
]), | ||
'B6' << | ||
match.block('Target', [ | ||
match.Goto('B4'), | ||
]), | ||
'B7' << | ||
match.block('Target', [ | ||
match.ClosureCall(), | ||
match.Goto('B4'), | ||
]), | ||
'B4' << | ||
match.block('Join', [ | ||
match.Return(), | ||
]), | ||
]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.