-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[wasm] Fix R2R codegen trap on async try/return/catch normal-completion branch #131287
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
+95
−4
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
50 changes: 50 additions & 0 deletions
50
src/tests/JIT/Regression/JitBlue/Runtime_131285/Runtime_131285.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,50 @@ | ||
| // 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 async | ||
| // exception-handling lowering. When an async method's try block completes | ||
| // normally by branching out early (a `return` after an `await`), the | ||
| // normal-completion branch was bound to a Block that ended at the try's own | ||
| // end cursor -- nested inside the exception-ref wrapper funclet -- so the | ||
| // branch landed on the wrapper's trailing validation `unreachable` and | ||
| // trapped (RuntimeError: unreachable) instead of resuming. | ||
| // | ||
| // The defect is in codegen, independent of whether the await actually | ||
| // suspends: `await Task.CompletedTask` still generates the state-machine | ||
| // normal-completion branch that traps. A completed await is used deliberately | ||
| // so the synchronous .GetAwaiter().GetResult() does not block the single wasm | ||
| // thread (blocking on incomplete work traps elsewhere in corelib on wasm). | ||
| // | ||
| // Reproduces only under crossgen wasm R2R (TargetOS=browser), where the | ||
| // unfixed JIT aborts the module (exit != 100 => test fails). Passes trivially | ||
| // on all other targets. | ||
|
|
||
| using System; | ||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
|
|
||
| public class Runtime_131285 | ||
| { | ||
| [Fact] | ||
| public static void TestEntryPoint() | ||
| { | ||
| // Sync [Fact]: the merged runner invokes this via a bare call, so drive | ||
| // the async method to completion synchronously here. RunAsync's MoveNext | ||
| // takes the normal-completion `return` path -- the edge that trapped | ||
| // under the unfixed wasm R2R JIT. | ||
| RunAsync().GetAwaiter().GetResult(); | ||
| } | ||
|
|
||
| private static async Task RunAsync() | ||
| { | ||
| try | ||
| { | ||
| await Task.CompletedTask; | ||
| return; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| GC.KeepAlive(ex); | ||
| } | ||
| } | ||
| } |
16 changes: 16 additions & 0 deletions
16
src/tests/JIT/Regression/JitBlue/Runtime_131285/Runtime_131285.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,16 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <Optimize>True</Optimize> | ||
| <!-- The bug is wasm R2R (crossgen) codegen. On non-browser legs this runs as | ||
| ordinary JIT/interp and passes trivially (expected). On the browser leg, | ||
| AlwaysUseCrossGen2 forces crossgen (exports RunCrossGen2=1) so the test is | ||
| actually compiled to wasm R2R and run under node -- otherwise a plain | ||
| browser leg runs it as normal JIT and silently false-passes without ever | ||
| exercising the fix. CrossGen2OutputFormat=wasm is set automatically for | ||
| TargetOS=browser (src/tests/Directory.Build.props). --> | ||
| <AlwaysUseCrossGen2 Condition="'$(TargetOS)' == 'browser'">true</AlwaysUseCrossGen2> | ||
| </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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.