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

[BUG] MemoryError on field assignment #224

Closed
1 task done
Furetur opened this issue Oct 17, 2024 · 1 comment
Closed
1 task done

[BUG] MemoryError on field assignment #224

Furetur opened this issue Oct 17, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Furetur
Copy link

Furetur commented Oct 17, 2024

Describe the bug
The SystemRDL compiler always checks if VALUE fits in WIDTH in the following construction: field {...} F[WIDTH] = VALUE.
However, this validation code crashes if WIDTH is too large.

For example, compiling the following code crashes the compiler (I compile with peakrdl dump main.rdl)

addrmap name {
    reg {
        field { } f[-1] = 1; // Here -1 becomes 18446744073709551614 according to the SystemRDL Spec
    } R;
};

Error:

Traceback (most recent call last):
  File "...", line 8, in <module>
    sys.exit(main())
  File ".../venv/lib/python3.8/site-packages/peakrdl/main.py", line 183, in main
    options.subcommand.main(importers, options)
  File ".../venv/lib/python3.8/site-packages/peakrdl/subcommand.py", line 151, in main
    top = process_input.elaborate(rdlc, parameters, options)
  File ".../venv/lib/python3.8/site-packages/peakrdl/process_input.py", line 145, in elaborate
    root = rdlc.elaborate(
  File ".../venv/lib/python3.8/site-packages/systemrdl/compiler.py", line 421, in elaborate
    walker.RDLWalker(skip_not_present=True).walk(root_node, ValidateListener(self.env))
  File ".../venv/lib/python3.8/site-packages/systemrdl/walker.py", line 159, in walk
    self.walk(child, *listeners)
  File ".../venv/lib/python3.8/site-packages/systemrdl/walker.py", line 159, in walk
    self.walk(child, *listeners)
  File ".../venv/lib/python3.8/site-packages/systemrdl/walker.py", line 159, in walk
    self.walk(child, *listeners)
  File ".../venv/lib/python3.8/site-packages/systemrdl/walker.py", line 150, in walk
    self.current_action = self.do_enter(node, listener)
  File ".../venv/lib/python3.8/site-packages/systemrdl/walker.py", line 176, in do_enter
    action = listener.enter_Component(node) or WalkerAction.Continue
  File ".../venv/lib/python3.8/site-packages/systemrdl/core/validate.py", line 44, in enter_Component
    prop_rule.validate(node, prop_value)
  File ".../venv/lib/python3.8/site-packages/systemrdl/properties/builtin.py", line 436, in validate
    if value >= (1 << node.width):
MemoryError

Version
systemrdl-compiler==1.27.3

Expected behavior
I expect the tool to not crash :)

It is possible to check if VALUE fits in WIDTH using logarithms instead of 1 << node.width. Maybe it will fix this issue

@amykyta3 amykyta3 added the bug Something isn't working label Dec 9, 2024
amykyta3 added a commit that referenced this issue Dec 18, 2024
@amykyta3
Copy link
Member

What an absurd bug 😆 thanks!

Fixed in a few places by using a comparison against the integer's .bit_length() instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants