Skip to content

Fix several open bugs: assertion failures, error reporting, and elaboration issues#1292

Open
apullin wants to merge 12 commits intosteveicarus:masterfrom
apullin:bugfix/multiple-issues
Open

Fix several open bugs: assertion failures, error reporting, and elaboration issues#1292
apullin wants to merge 12 commits intosteveicarus:masterfrom
apullin:bugfix/multiple-issues

Conversation

@apullin
Copy link

@apullin apullin commented Jan 23, 2026

Summary

This PR fixes 12 bugs from the GitHub issue tracker, focusing on:

  • Assertion failures converted to proper error messages
  • Elaboration issues with arrays, structs, and uwire types
  • Minor fixes in error reporting and path handling

Bugs Fixed

Issue Description
#1112 Report error for invalid $bits argument instead of assertion
#670 Allow class methods named same as class
#1140 Report error for x/z in vector dimensions
#1170 Skip $unit scope in tgt-sizer
#1187 Quote paths in driver to allow spaces in -B flag
#1267 Allow wire logic connected to uwire port to have multiple drivers
#1268 Allow variables to be driven by primitive gate outputs
#521 Allow variable indices in outer packed dimensions
#1134 Allow struct member access in unpacked array of packed structs
#1265 Allow continuous assignment of single-element unpacked arrays
#1220 Allow uwire arrays as input ports
#716 Report error for incompatible task argument types instead of assertion

Additional Regression Tests

Testing

Each fix includes a regression test in ivtest/ivltests/ added to regress-sv.list.

@caryr
Copy link
Collaborator

caryr commented Jan 24, 2026

Thank you for all your work on this. I will review this soon and pull all this in before we release 13.0.

One note: for #1140 I had assigned this to myself and have mostly completed it thought there are still a couple places I had not finished and there is a proposed patch for #1187. It would have been best if you had asked about these before making changes and if these were individual patches it would make them easier to review and compare to the work others have already done.

@apullin
Copy link
Author

apullin commented Jan 24, 2026

@caryr I'll close the PR and resubmit individual per-bug PR's that are non-overlapping.

Also this is < 1 day work with Claude Code, I did very little.

@caryr
Copy link
Collaborator

caryr commented Jan 24, 2026

Okay, let me review the changes in more detail so I can give some constructive feedback before you submit again. I did notice a couple formatting items, duplicate code, etc. Lets get Claude on the right track from the beginning.

Overall things looks good from my initial scan.

@caryr
Copy link
Collaborator

caryr commented Jan 24, 2026

For the #1187 change take a look at the #1190 pull request. It looks like that covers all the changes you made and then there were issues with windows. I'm guessing, but I assume the windows changes started getting out of hand and that needed to be resolved in a reasonable manner before this became an official pull request.

I'm going to start a discussion regarding the use of AI generated changes in iverilog. Look for that in the discussion area and please contribute. There a a few things I want to make sure we do correct from the beginning.

@caryr
Copy link
Collaborator

caryr commented Jan 24, 2026

See #1293 for the AI discussion.

@apullin apullin force-pushed the bugfix/multiple-issues branch from 5d30612 to c5f2ab4 Compare January 25, 2026 02:45
@apullin
Copy link
Author

apullin commented Jan 25, 2026

Removed commits for #1140 and #1187, repushed the branch. Each commit builds and passes all tests.

LMK if you'd prefer me to drop this stacked PR, and do a separate PR w/ notes & theory of the fix for each bugfix.

@apullin apullin force-pushed the bugfix/multiple-issues branch 3 times, most recently from a565efb to 87dfed3 Compare January 25, 2026 14:44
@apullin
Copy link
Author

apullin commented Jan 25, 2026

Duplicate code for the fix for #1134 was removed. Stack was re-ordered because the tests did fail at one commit, but was then fixed at a later one.
(my yml to force github actions was briefly included then removed - these pushes are so "noisy" in this PR view)

Formatting - it seems to be a little inconsistent. My only known solution to this is to adopt a .clangformat and do a one-time reformat of the entire repo, and then stick to that.
An example here: apullin@45d3892
But it touches essentially every line (due to the unusual 6-space indent).

@caryr
Copy link
Collaborator

caryr commented Feb 1, 2026

I'll look at this and comment more once I get the 13.0 release completed. I've been busy with my work and personal commitments so am behind getting this finished.

apullin and others added 12 commits March 9, 2026 20:47
When $bits() is called with an undefined identifier, the compiler now
properly reports an error instead of silently returning 0.

The fix checks if the argument expression has type IVL_VT_NO_TYPE after
test_width() processing (indicating the identifier couldn't be resolved),
and triggers elaboration to produce a proper error message.

Includes regression test: br_gh1112

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Modified grammar in parse.y to use identifier_name instead of IDENTIFIER
in function/task declaration rules and hierarchy_identifier rule. This
allows TYPE_IDENTIFIER tokens (which class names become after definition)
to be used as method names.

Changes:
- Function declaration rules (lines 1585, 1605, 1631)
- Task declaration rules (lines 2445, 2472, 2501)
- hierarchy_identifier member access (line 4471)

Includes regression test: br_gh670

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The tgt-sizer target now skips IVL_SCT_PACKAGE scopes (the SystemVerilog
$unit compilation unit scope) instead of erroring. This allows sizer to
work with -g2012 and other SystemVerilog modes.

Includes regression test: br_gh1170

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…e multiple drivers

TODO: Decide how resolved net types (tri0/tri1/triand/trior) should interact with uwire in a shared nexus.
…outputs

Per IEEE 1800-2017 6.5, variables can be written by one port, including
primitive gate outputs. The code incorrectly disallowed this with the
comment "Gates can never have variable output ports."

Changed elaborate_lnet/elaborate_bi_net calls for gate outputs to pass
true for var_allowed_in_sv, allowing variables as single-driver outputs.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
In multi-dimensional packed arrays, allow variable indices in the outer
(prefix) dimensions, not just the final dimension. For example:

  logic [3:0][3:0] a;
  for (int i=0; i<4; i++)
    a[i][3] = 1;  // Previously error, now works

The fix checks if any packed prefix indices are non-constant. If so,
use collapse_array_exprs() to compute the bit offset as an expression
rather than requiring constant indices.

This removes an artificial restriction that had no justification in
the IEEE standard, as noted by maintainers in the GitHub issue.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
… packed structs

When accessing a member of a packed struct within an unpacked array
(e.g., `tests[0].a` where `tests` is `test_t tests[0:1]`), the
assertion `base_index.size()+1 == net->packed_dimensions()` would fail
because unpacked indices were incorrectly included in base_index.

The fix:
1. Separate unpacked indices from packed indices before calling
   check_for_struct_members()
2. Compute the word index for unpacked array access using
   normalize_variable_unpacked()
3. Pass the word index to check_for_struct_members(), which now
   creates NetESignal with the proper word selector

This allows expressions like `array_of_structs[i].member` to work
correctly, selecting the right array element before extracting the
packed struct member.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Uwire arrays were triggering assertion failures because they were
kept virtualized (pins array NULL) like reg arrays. However, unlike
reg arrays, uwire arrays used as input ports need their nexuses
initialized for the target code generation to work properly.

Two changes:
1. elab_sig.cc: Devirtualize pins for UNRESOLVED_WIRE (uwire) type,
   same as regular WIRE type.
2. t-dll-api.cc: Update assertion in ivl_signal_nex to also accept
   IVL_SIT_UWIRE when pins array is NULL.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
When an undimensioned (dynamic) array was passed to a task parameter
expecting a simple vector, the compiler would crash with an assertion
failure because the switch handling type casts didn't know how to
handle IVL_VT_DARRAY type.

Changed the assertion to emit a proper error message about type
incompatibility and continue processing, allowing the compiler to
report the error gracefully instead of crashing.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…npacked arrays

The original check used `pin_count() > 1` to detect whole-array
assignments, which missed single-element arrays like `[0:0]` where
pin_count is 1.

The fix checks for whole-array assignments by:
1. Multi-element arrays (pin_count > 1) - always whole-array
2. Single-element unpacked arrays - check if the lval expression
   has array indices. If no indices, it's a whole-array reference.

This correctly distinguishes between:
- `assign arr = expr` (whole array) -> elaborate_unpacked_array_
- `assign arr[i] = expr` (indexed element) -> normal path

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This bug was fixed by the steveicarus#1265 fix. The error 'Array needs an array
index here' no longer occurs for unpacked array literals in
continuous assignments.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…n confusion

This bug was fixed by the steveicarus#1265 fix. Single-element unpacked arrays
of packed types (like byte [0:0]) now work correctly in continuous
assignments.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@apullin apullin force-pushed the bugfix/multiple-issues branch from 87dfed3 to 314638a Compare March 10, 2026 03:48
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