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

Mechanism to warn about integer truncation in constants #142

Open
mkorbel1 opened this issue Jul 28, 2022 · 3 comments
Open

Mechanism to warn about integer truncation in constants #142

mkorbel1 opened this issue Jul 28, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@mkorbel1
Copy link
Contributor

Motivation

Sometimes one might want to create a Const which requires passing an integer, but the integer doesn't "fit" in the specified width of the constant signal. The current behavior is just truncation, meaning the constant value doesn't match the value of the original int.

Desired solution

A warning, error, exception, or something along those lines making it more difficult to accidentally truncate the desired constant value.

@mkorbel1 mkorbel1 added the enhancement New feature or request label Jul 28, 2022
@mkorbel1
Copy link
Contributor Author

Related discussion: #335

@mkorbel1
Copy link
Contributor Author

This is also interesting for LogicValue construction

@mkorbel1
Copy link
Contributor Author

A couple considerations:

  • Const should have a flag like allowTruncation or something to override
  • negative numbers shouldn't flag this (e.g. -1 has sign extension). One possible way to check is to make sure the int/bigint value after conversion is the same if input is negative int/bigint

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant