Fix large array initialization for I/O ports (#6904)#6918
Draft
neeruuppalapati wants to merge 2 commits intoverilator:masterfrom
Draft
Fix large array initialization for I/O ports (#6904)#6918neeruuppalapati wants to merge 2 commits intoverilator:masterfrom
neeruuppalapati wants to merge 2 commits intoverilator:masterfrom
Conversation
added 2 commits
January 12, 2026 16:14
When unpacked arrays with >256 elements and >64-bit packed width are assigned using aggregate initialization, Verilator generated invalid C++ code with malformed initializers. Two issues were fixed: - V3Slice: Don't skip slice expansion for I/O ports since they use raw C arrays that don't support aggregate initialization - V3EmitCFunc: Exclude InitArray from wide assignment optimization to ensure proper LHS emission
When unpacked arrays with >256 elements and >64-bit packed width are assigned using aggregate initialization, Verilator generated invalid C++ code with malformed initializers. Two issues were fixed: - V3Slice: Don't skip slice expansion for I/O ports since they use raw C arrays that don't support aggregate initialization - V3EmitCFunc: Exclude InitArray from wide assignment optimization to ensure proper LHS emission
wsnyder
reviewed
Jan 12, 2026
Member
wsnyder
left a comment
There was a problem hiding this comment.
Appreciate your first pull! Some minor comments:
| // Skip optimization if array is too large | ||
| // Check if LHS contains I/O ports - they use raw C arrays which can't be assigned with = | ||
| const bool hasIO | ||
| = nodep->lhsp()->exists([&](const AstVarRef* refp) -> bool { return refp->varp()->isIO(); }); |
Member
There was a problem hiding this comment.
Suggested change
| = nodep->lhsp()->exists([&](const AstVarRef* refp) -> bool { return refp->varp()->isIO(); }); | |
| = nodep->lhsp()->exists([&](const AstVarRef* refp) -> bool { return refp->varp()->isPrimaryIO(); }); |
| @@ -0,0 +1,25 @@ | |||
| // -*- mode: C++; c-file-style: "cc-mode" -*- | |||
Member
There was a problem hiding this comment.
This file shouldn't be needed, the driver will make it.
| clk | ||
| ); | ||
|
|
||
| input clk; |
Member
There was a problem hiding this comment.
Please use 2 spaces per indent level in new files to match edaplayground/verilog-format, thanks.
Member
|
Marking draft for now; I'm hoping you can get back to this & address the comments, once you do & tests pass please mark non-draft and I'll review again. |
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.
When you have a large array (>256 elements) with wide elements (>64 bits) on an output port like this:
Verilator generated broken C++ code that wouldn't compile. The generated code was missing the left-hand side of the assignment, producing something like {{0, 0, ...}}; instead of my_array = {{0, 0, ...}};. I believe this was introduced in commit e2f5854 as mentioned in the GH issue. The problem seems to be that output ports are declared as raw C arrays and the assignment is broken, whilst VLUnpacked does support this. I made the below changes, let me know if this is short sighted, there are bigger things to do, I also added some tests.