[ImportVerilog] Resolve modport member accesses through interface ports#10398
Open
[ImportVerilog] Resolve modport member accesses through interface ports#10398
Conversation
In-body accesses like `bus.member` (where `bus` is an `Iface.modport` port) are produced by slang as `HierarchicalValueExpression`s. They were mishandled in two ways: 1. `HierarchicalNames.cpp` recorded them as cross-instance hierarchical references, adding spurious `hierPath` inputs to the module signature that the instance call site never filled in. This produced `unsupported port` whenever such a module was instantiated. 2. The expression's symbol is the `ModportPortSymbol`, not the interface body variable. Body-level lookups via `valueSymbols`, which keyed on the body variable, missed it. Fix: skip via-iface-port refs in `HierarchicalNames.cpp` using slang's `isViaIfacePort()`, and thread the `ModportPortSymbol` through `FlattenedIfacePort` so `Structure.cpp` registers both keys (body variable + modport port symbol) in `valueSymbols`. Slang already enforces modport directionality during elaboration, so the fix does not bypass any access checks. Also add a regression test exercising in-body read of a modport input and write of a modport output. Assisted-by: Claude Code:claude-opus-4-7
Scheremo
approved these changes
May 9, 2026
Contributor
Scheremo
left a comment
There was a problem hiding this comment.
Got a nit, but otherwise LGTM!
Comment on lines
+1310
to
+1314
| if (auto *mppSym = fp.modportPortSym | ||
| ? fp.modportPortSym->as_if<slang::ast::ValueSymbol>() | ||
| : nullptr; | ||
| mppSym && mppSym != valueSym) | ||
| valueSymbols.insert(mppSym, portValue); |
Contributor
There was a problem hiding this comment.
Suggested change
| if (auto *mppSym = fp.modportPortSym | |
| ? fp.modportPortSym->as_if<slang::ast::ValueSymbol>() | |
| : nullptr; | |
| mppSym && mppSym != valueSym) | |
| valueSymbols.insert(mppSym, portValue); | |
| slang::ast::ValueSymbol *mppSym = nullptr; | |
| if (fp.modportPortSym) { | |
| mppSym = fp.modportPortSym->as_if<slang::ast::ValueSymbol>(); | |
| } | |
| if (mppSym && mppSym != valueSym) { | |
| valueSymbols.insert(mppSym, portValue); | |
| } |
nit: Might be nice to take this apart, looks like that's three checks rolled into one statement
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.
In-body accesses like
bus.member(wherebusis anIface.modportport) are produced by slang asHierarchicalValueExpressions. They were mishandled in two ways:HierarchicalNames.cpprecorded them as cross-instance hierarchical references, adding spurioushierPathinputs to the module signature that the instance call site never filled in. This producedunsupported portwhenever such a module was instantiated.The expression's symbol is the
ModportPortSymbol, not the interface body variable. Body-level lookups viavalueSymbols, which keyed on the body variable, missed it.Fix: skip via-iface-port refs in
HierarchicalNames.cppusing slang'sisViaIfacePort(), and thread theModportPortSymbolthroughFlattenedIfacePortsoStructure.cppregisters both keys (body variable + modport port symbol) invalueSymbols. Slang already enforces modport directionality during elaboration, so the fix does not bypass any access checks.Also add a regression test exercising in-body read of a modport input and write of a modport output.
Assisted-by: Claude Code:claude-opus-4-7