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

Fixing undefined behaviours #4879

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Fixing undefined behaviours #4879

wants to merge 2 commits into from

Conversation

KrystalDelusion
Copy link
Member

@KrystalDelusion KrystalDelusion commented Jan 30, 2025

What are the reasons/motivation for this change?

#4845 (and #4844 (comment)) reveal undefined behaviors in the Yosys code. This PR aims to resolve them.

Explain how this is achieved.

  • kernel/celledges.cc
    b_width_capped already exists for preventing arithmetic overflow, limiting the value of b_width to 30. This just changes the left shifts to also use it. The caveat of incorrect results for extremely large values of a_width still applies, as does the improbability of that actually happening. This fixes synth failure #4844 (or at least, the floating point exception; the circuit still isn't valid but I think that's fine).
  • frontends/ast/simplify.cc
    In the nowrshmsk handling, log2(0) returns -inf, which gives undefined behaviour when casting to an int. So catch the case when the stride is 0 and just set the stride_width to 0.

If applicable, please suggest to reviewers how they can test the change.

Follow instructions for testing #4845 on this branch

`b_width_capped` already exists for preventing arithmetic overflow, limiting the value of `b_width` to 30.  This just changes the left shifts to also use it.
The caveat of incorrect results for extremely large values of `a_width` still applies, as does the improbability of that actually happening.
This fixes #4844 (or at least, the floating point exception; the circuit still isn't valid but I think that's fine).
@KrystalDelusion
Copy link
Member Author

@povik the b_width_capped addition and previous left shift checks have you on the blame, so if you could sanity check that the celledges changes are okay I would appreciate it :)

log2(0) returns -inf, which gives undefined behaviour when casting to an int.  So catch the case when it's 0 just set the width to 0.
@KrystalDelusion KrystalDelusion marked this pull request as ready for review January 30, 2025 23:45
@whitequark
Copy link
Member

I don't quite understand that code so I don't feel like I can sign off on it, apologies.

@povik
Copy link
Member

povik commented Jan 31, 2025

@KrystalDelusion sure thing, and thanks for taking this up

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.

synth failure
3 participants