Skip to content
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

[wasm-reduce] Do not crash on non-func element segments #6778

Merged
merged 4 commits into from
Jul 26, 2024

Conversation

tlively
Copy link
Member

@tlively tlively commented Jul 19, 2024

Generalize the code for simplifying element segments to handle more than
just null and funcref elements.

@tlively tlively requested a review from kripken July 19, 2024 23:10
}
// Replace the element if it is different from our first "zero"
// element.
return !ExpressionAnalyzer::equal(first, elem);
Copy link
Member

Choose a reason for hiding this comment

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

This looks flipped? Before we returned f->func == e->func which meant we return true when they were equal.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed!

Base automatically changed from threads-subtype-depths to main July 23, 2024 20:03
Generalize the code for simplifying element segments to handle more than
just null and funcref elements.
(elem (i32.const 0) $f0 $f0 $f1 $f2 $f0 $f3 $f0)
(elem (table 1) (i32.const 0) i31ref (item (ref.i31 (i32.const 0))) (item (ref.i31 (i32.const 1))))
Copy link
Member

Choose a reason for hiding this comment

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

If you make one of these values different than 0 and 1 then I think it will not be removed, which would show that we keep things that are needed.

Suggested change
(elem (table 1) (i32.const 0) i31ref (item (ref.i31 (i32.const 0))) (item (ref.i31 (i32.const 1))))
(elem (table 1) (i32.const 0) i31ref (item (ref.i31 (i32.const 0))) (item (ref.i31 (i32.const 42))))

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, thanks!

(func $f5 (result i32)
(i32.add
(i31.get_s (table.get 1 (i32.const 0)))
(i31.get_u (table.get 1 (i32.const 1)))
Copy link
Member

Choose a reason for hiding this comment

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

With the suggestion above I think one of these two operations will get reduced but not the other.

(elem (i32.const 0) $f0 $f0 $f1 $f2 $f0 $f3 $f0)
(elem (table 1) (i32.const 0) i31ref (item (ref.i31 (i32.const 0))) (item (ref.i31 (i32.const 42))))
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, now it isn't removing anything here... maybe add a final item with some value (doesn't matter what)?

Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

Sorry for the iteration here, but now I think this fully tests the change, nice!

@tlively tlively enabled auto-merge (squash) July 23, 2024 23:13
@tlively tlively disabled auto-merge July 26, 2024 19:50
@tlively tlively merged commit f938154 into main Jul 26, 2024
12 of 13 checks passed
@tlively tlively deleted the fix-reduce-segment-cast branch July 26, 2024 19:50
@gkdn gkdn mentioned this pull request Aug 31, 2024
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.

None yet

2 participants