Skip to content

Tcheck: treat trivially false range checks as errors#151

Merged
alastairreid merged 1 commit into
masterfrom
areid-report-failing-asserts
Jun 23, 2026
Merged

Tcheck: treat trivially false range checks as errors#151
alastairreid merged 1 commit into
masterfrom
areid-report-failing-asserts

Conversation

@alastairreid

@alastairreid alastairreid commented Jun 15, 2026

Copy link
Copy Markdown

Tcheck: treat trivially false range checks as errors

This makes expressions like '0b1[3:0]' or '3 / 0' into typechecking errors instead of just runtime errors.

Note that this only applies when

  1. Expressions only involve literal constants.

    e.g. 'x > x+1' or '0 <= x && x < 0' will be checked at runtime.

  2. Assertions that are automatically inserted by the compiler
    to check for errors like

    • x / 0
    • x / y when x or y is negative
    • my_array[i] when i is outside the bounds of the array
    • b[i], b[i +: 8], b[i -: 8], b[i *: 8] when those accesses
      go outside the bounds of the bitvector
    • let x : {0..7} := 15; // i.e., assigning an out of bounds value
  3. Runtime error checks are enabled (using --runtime-errors)

So this does not guarantee to detect all errors.
In fact, it will miss quite a lot of possible errors.

But it will catch completely silly errors and, in particular, it will catch errors resulting from the forthcoming change to treat hex numbers as bitvectors that has resulted in a lot of expressions of the form "0x1[31:0]" creating latent runtime errors.

This makes expressions like '0b1[3:0]' or '3 / 0' into typechecking errors
instead of just runtime errors.

Note that the checks are only performed if you use --runtime-errors
@alastairreid alastairreid merged commit 759375a into master Jun 23, 2026
1 check passed
@alastairreid alastairreid deleted the areid-report-failing-asserts branch June 23, 2026 11:14
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