Verilog: resolve function calls in generate/named block scopes - #2116
Draft
kroening wants to merge 1 commit into
Draft
Verilog: resolve function calls in generate/named block scopes#2116kroening wants to merge 1 commit into
kroening wants to merge 1 commit into
Conversation
A function or task declared inside a generate block (or named block) is registered in the symbol table with the enclosing block in its name, e.g. main.gen_block.plus_one. Variable resolution already searches the enclosing named blocks, but convert_expr_function_call only tried the current module and the compilation-unit scope, so a call to such a function was rejected with "unknown function". Resolve function-call identifiers the same way variables are resolved: search the enclosing named blocks first (innermost first), then the current module, then the compilation-unit scope. Per IEEE 1800-2017 27.2, function declarations inside generate blocks are usable within that scope. This flips regression/verilog/generate/generate-function1 from KNOWNBUG to CORE.
kroening
marked this pull request as draft
August 21, 2026 18:55
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.
Summary
IEEE 1800-2017 §27.2 permits function declarations inside generate blocks; the function is usable within the scope of the generate block. Such a function is registered in the symbol table with the enclosing block in its name (e.g.
main.gen_block.plus_one), viahierarchical_identifier, which honors thenamed_blocksstack.Variable resolution (
verilog_typecheck_exprt::resolve) already iterates the enclosing named blocks, so nets/regs in a generate block resolve correctly. Butconvert_expr_function_callused its own lookup that only triedmodule_instance + "." + base_nameand then the compilation-unit scope — it never searched the enclosing named/generate-block scopes. A call to such a function was therefore rejected withunknown function.This change resolves function-call identifiers the same way variables are resolved: search the enclosing named blocks first (innermost first), then the current module, then the compilation-unit scope.
This fixes the underlying bug behind the KNOWNBUG test added in #2114 and flips
regression/verilog/generate/generate-function1fromKNOWNBUGtoCORE.Testing
make -C regression/verilog test— full Verilog suite passes;generate/generate-function1.desc [OK].[main.gen_block.p1] always main.gen_block.val == 42: PROVED.generate forblock resolves and proves for each unrolled instance (main.g[0].p,main.g[1].p).