Repository navigation
JIT: don't fall through from a Wasm callfinally across a try_table end #134758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
25c436c
JIT: don't fall through from a Wasm callfinally across a try_table end
lewing f685c06
Add Runtime_134264 regression test and verify Wasm fall-through targets
lewing ddb3e02
Trim genCallFinally comment
lewing 4414423
Add example Wasm to fall-through verification comment
lewing File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
105 changes: 105 additions & 0 deletions
105
src/tests/JIT/Regression_2/Runtime_134264/Runtime_134264.cs
This file contains hidden or 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,105 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| // Regression test for a WebAssembly R2R (crossgen) codegen bug in finally | ||
| // calls. When a callfinally's continuation was the lexically next block, | ||
| // codegen fell through to it without a branch. If a try_table ended between | ||
| // the two, the fall-through landed on the validation `unreachable` emitted | ||
| // after the try_table `end` and trapped (RuntimeError: unreachable). | ||
| // | ||
| // The shape needs a user try/finally that ends the async method (so the | ||
| // continuation is outside the state machine's try/catch) and a finally too | ||
| // large to be cloned onto the normal path. | ||
| // | ||
| // Reproduces only under crossgen wasm R2R (TargetOS=browser). Passes trivially | ||
| // on all other targets. | ||
|
|
||
| using System; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
|
|
||
| public class Runtime_134264 | ||
| { | ||
| private static int s_value; | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| private static void Touch(int value) => s_value += value; | ||
|
|
||
| private static async Task TryCatchFinallyAsync(bool enter) | ||
| { | ||
| bool entered = false; | ||
| try | ||
| { | ||
| if (enter) | ||
| { | ||
| await Task.CompletedTask; | ||
| entered = true; | ||
| } | ||
|
|
||
| Touch(1); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| GC.KeepAlive(ex); | ||
| Touch(-100); | ||
| } | ||
| finally | ||
| { | ||
| if (entered) | ||
| { | ||
| Touch(1); Touch(2); Touch(3); Touch(4); Touch(5); Touch(6); Touch(7); Touch(8); | ||
| Touch(9); Touch(10); Touch(11); Touch(12); Touch(13); Touch(14); Touch(15); Touch(16); | ||
| } | ||
|
|
||
| Touch(1000); | ||
| } | ||
| } | ||
|
|
||
| private static async Task NestedTryFinallyAsync(bool enter) | ||
| { | ||
| bool entered = false; | ||
| try | ||
| { | ||
| try | ||
| { | ||
| if (enter) | ||
| { | ||
| await Task.CompletedTask; | ||
| entered = true; | ||
| } | ||
|
|
||
| Touch(1); | ||
| } | ||
| finally | ||
| { | ||
| if (entered) | ||
| { | ||
| Touch(1); Touch(2); Touch(3); Touch(4); Touch(5); Touch(6); Touch(7); Touch(8); | ||
| Touch(9); Touch(10); Touch(11); Touch(12); Touch(13); Touch(14); Touch(15); Touch(16); | ||
| } | ||
|
|
||
| Touch(1000); | ||
| } | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| GC.KeepAlive(ex); | ||
| Touch(-100); | ||
| } | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData(true, 1137)] | ||
| [InlineData(false, 1001)] | ||
| public static async Task TestEntryPoint(bool enter, int expected) | ||
| { | ||
| s_value = 0; | ||
| await TryCatchFinallyAsync(enter); | ||
| Assert.Equal(expected, s_value); | ||
|
|
||
| s_value = 0; | ||
| await NestedTryFinallyAsync(enter); | ||
| Assert.Equal(expected, s_value); | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
src/tests/JIT/Regression_2/Runtime_134264/Runtime_134264.csproj
This file contains hidden or 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,8 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <Optimize>True</Optimize> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <Compile Include="$(MSBuildProjectName).cs" /> | ||
| </ItemGroup> | ||
| </Project> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.