-
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.
[cfe/ffi] Only keep
Finalizable
s alive after their declaration
We were adding fences around the variable declaration expressions including the variable that was not declared. This led to verification errors and crashes when not running the verifier. `Verification error: Variable 'VariableDeclarationImpl(final MyFinalizable myFinalizable)' used out of scope.` TEST=pkg/vm/testcases/transformations/ffi/regress_49075.dart Closes: #49075 Change-Id: I1f07f0343d29c3efb3c63c0aa0e3f20338b5c653 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/246520 Commit-Queue: Daco Harkes <[email protected]> Reviewed-by: Jens Johansen <[email protected]>
- Loading branch information
Showing
3 changed files
with
62 additions
and
2 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
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,14 @@ | ||
// 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. | ||
|
||
import 'dart:ffi'; | ||
|
||
Future<void> main(List<String> arguments) async { | ||
// ignore: unused_local_variable | ||
final myFinalizable = await MyFinalizable(); | ||
} | ||
|
||
class MyFinalizable implements Finalizable { | ||
MyFinalizable(); | ||
} |
45 changes: 45 additions & 0 deletions
45
pkg/vm/testcases/transformations/ffi/regress_49075.dart.expect
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,45 @@ | ||
library #lib /*isNonNullableByDefault*/; | ||
import self as self; | ||
import "dart:core" as core; | ||
import "dart:ffi" as ffi; | ||
import "dart:_internal" as _in; | ||
import "dart:async" as asy; | ||
|
||
import "dart:ffi"; | ||
|
||
class MyFinalizable extends core::Object implements ffi::Finalizable { | ||
constructor •() → self::MyFinalizable | ||
: super core::Object::•() { | ||
; | ||
_in::reachabilityFence(this); | ||
} | ||
} | ||
static method main(core::List<core::String> arguments) → asy::Future<void> /* futureValueType= void */ /* originally async */ { | ||
final asy::_Future<void> :async_future = new asy::_Future::•<void>(); | ||
core::bool* :is_sync = false; | ||
void :return_value; | ||
(dynamic) → dynamic :async_op_then; | ||
(core::Object, core::StackTrace) → dynamic :async_op_error; | ||
core::int :await_jump_var = 0; | ||
dynamic :await_ctx_var; | ||
dynamic :saved_try_context_var0; | ||
function :async_op(dynamic :result_or_exception, dynamic :stack_trace) → dynamic yielding | ||
try { | ||
#L1: | ||
{ | ||
[yield] let dynamic #t1 = asy::_awaitHelper(new self::MyFinalizable::•(), :async_op_then, :async_op_error) in null; | ||
final self::MyFinalizable myFinalizable = _in::unsafeCast<self::MyFinalizable>(:result_or_exception); | ||
_in::reachabilityFence(myFinalizable); | ||
} | ||
asy::_completeWithNoFutureOnAsyncReturn(:async_future, :return_value, :is_sync); | ||
return; | ||
} | ||
on dynamic catch(dynamic exception, core::StackTrace stack_trace) { | ||
asy::_completeOnAsyncError(:async_future, exception, stack_trace, :is_sync); | ||
} | ||
:async_op_then = asy::_asyncThenWrapperHelper(:async_op); | ||
:async_op_error = asy::_asyncErrorWrapperHelper(:async_op); | ||
:async_op(null, null){() → dynamic}; | ||
:is_sync = true; | ||
return :async_future; | ||
} |