Skip to content

Fix IRBuilder location tracking of If starts #7617

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 3 commits into from
May 22, 2025

Conversation

kripken
Copy link
Member

@kripken kripken commented May 21, 2025

The old code forgot the If scope when it started the Else, so any if-else would get
a binary location span that started in the else (and ends in the right place).

To fix this, note the if start location when we have it, and don't trample.

Fixes branch hints on if-elses.

@kripken kripken requested a review from tlively May 21, 2025 20:22
auto end = BinaryLocation(*binaryPos - codeSectionOffset);
// Some expressions already have their start noted, and we are just seeing
// their last segment (like an Else).
auto iter = func->expressionLocations.find(expr);
Copy link
Member

Choose a reason for hiding this comment

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

Let's always do just one lookup by using .insert() here to get an iterator, then fixing up just the end if an entry already exists.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.


// Note the start of the if (which will be lost as the If is closed and the
// Else begins, but the if spans them both).
func->expressionLocations[iff].start = scope.startPos - codeSectionOffset;
Copy link
Member

Choose a reason for hiding this comment

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

Can we either fix this for try-catch as well, or add a TODO to do so?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a TODO. I'm not sure offhand how to handle multiple catches. Anyhow, only If is urgent atm.

@@ -259,6 +259,128 @@
)
)

;; CHECK: (func $branch-hints-if-else (type $0) (param $x i32)
Copy link
Member

Choose a reason for hiding this comment

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

In addition to this test, can we have another test that directly shows the correct binary offsets? Or do we not have a way to print IR annotated with binary offsets?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, we don't have an option to show binary offsets by a flag. We show them when DWARF sections exist, or code annotations, atm. Might be worth adding though.

@kripken kripken merged commit 7607db6 into WebAssembly:main May 22, 2025
15 checks passed
@kripken kripken deleted the irbuilder.if.loc branch May 22, 2025 15:31
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.

2 participants