Skip to content

Conversation

@sbomer
Copy link
Member

@sbomer sbomer commented Aug 11, 2022

Thanks for sharing the fix @vitek-karas. I cleaned it up a little to be more specific (existing tests which ended in removed ret instructions - for example in a removed else branch - were failing), and changed the test to check the instruction sequence.

This is intended to fix dotnet/runtime#73474. I had trouble creating a repro of the original issue encountered on runtime bits, but the new testcase exhibits what looks like the same issue.

To me it would feel like a cleaner fix to rewrite the always-taken conditional branches to be unconditional branches, but maybe there is some reason we don't do so today. The current fix has lower risk since it is so specifically targeted.

@sbomer sbomer requested a review from marek-safar as a code owner August 11, 2022 22:22
@sbomer sbomer requested a review from vitek-karas August 11, 2022 22:25
Copy link
Member

@vitek-karas vitek-karas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is currently not written to handle replacing instruction sequences of various length for conditions - in this case we would have to remove the ldc.i4.1 and brtrue.s to replace it with a simple br.s. Obviously doable, but would require much more code churn.

#2905 runs into a similar limitation. I haven't look in detail if we could use the same approach for both though. In any case I think this targeted fix is OK for 7.

@sbomer sbomer merged commit d559347 into dotnet:main Aug 12, 2022
agocke pushed a commit to dotnet/runtime that referenced this pull request Nov 16, 2022
This prevents invalid IL in situations where removing the last
instruction of a method would result in the last instruction
being a conditional branch. There needs to be some IL in the
not-taken branch for the IL to be valid, so this fixes the issue
by injecting "ldnull; throw" at the end.

Co-authored-by: vitek-karas <[email protected]>
Co-authored-by: Adam Sitnik <[email protected]>

Commit migrated from dotnet/linker@d559347
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[wasm] AOT compilation failing for System.Private.CoreLib in System.Runtime.Tests

3 participants