Verilog: fix array index direction for descending and ascending ranges#1729
Merged
tautschnig merged 1 commit intomainfrom Mar 13, 2026
Merged
Verilog: fix array index direction for descending and ascending ranges#1729tautschnig merged 1 commit intomainfrom
tautschnig merged 1 commit intomainfrom
Conversation
d71c782 to
c301e4c
Compare
Arrays declared with descending ranges (e.g., [4:0]) or ascending ranges with non-zero offsets were not correctly mapping Verilog indices to internal array indices. This affected both packed and unpacked arrays. For unpacked arrays, the Verilog index is now adjusted to the internal index based on the range direction and offset. For packed arrays, the assignment pattern operands are reversed for descending ranges so that internal index 0 corresponds to Verilog index 0, and the bitvector lowering is updated to match. Per IEEE 1800-2017 section 10.9.1, assignment patterns assign elements left-to-right starting from the left index of the range.
c301e4c to
bbd1589
Compare
tautschnig
approved these changes
Mar 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Arrays declared with descending ranges (e.g.,
[4:0]) or ascending ranges with non-zero offsets were not correctly mapping Verilog indices to internal array indices. This affected both packed and unpacked arrays.Problem
For a descending range like
int my_array[4:0], the assignment pattern'{ 1, 2, 3, 4, 5 }should assign index 4=1, index 3=2, ..., index 0=5 per IEEE 1800-2017 §10.9.1. However,my_array[0]was returning 1 instead of 5 because no index adjustment was performed.The same issue affected packed arrays like
bit [4:0][31:0].Fix
convert_bit_select_expr()based on range direction and offset.to_bitvector()in the lowering to match the new convention.ID_C_increasingon multi-dimensional packed array types (was previously missing).Test updates
packed_direction1andunpacked_direction1: promoted from KNOWNBUG to COREarray_conversion3: updated expectations from REFUTED to PROVEDarray_in_struct1: corrected assertions to match IEEE 1800-2017 descending range semantics