Skip to content

Verilog: resolve function calls in generate/named block scopes - #2116

Draft
kroening wants to merge 1 commit into
mainfrom
kroening/generate-block-function
Draft

Verilog: resolve function calls in generate/named block scopes#2116
kroening wants to merge 1 commit into
mainfrom
kroening/generate-block-function

Conversation

@kroening

Copy link
Copy Markdown
Collaborator

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), via hierarchical_identifier, which honors the named_blocks stack.

Variable resolution (verilog_typecheck_exprt::resolve) already iterates the enclosing named blocks, so nets/regs in a generate block resolve correctly. But convert_expr_function_call used its own lookup that only tried module_instance + "." + base_name and then the compilation-unit scope — it never searched the enclosing named/generate-block scopes. A call to such a function was therefore rejected with unknown 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-function1 from KNOWNBUG to CORE.

Testing

  • make -C regression/verilog test — full Verilog suite passes; generate/generate-function1.desc [OK].
  • The property now proves: [main.gen_block.p1] always main.gen_block.val == 42: PROVED.
  • Also verified a function declared in a generate for block resolves and proves for each unrolled instance (main.g[0].p, main.g[1].p).

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
kroening marked this pull request as draft August 21, 2026 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant