Fix assertion failure when elaborating a void function call (issue #318)

Depending on the order of elaboration, a function may not have been
elaborated before a call to it is elaborated, so don't assert that it
has been. As an optimisation, try to elaborate it on the fly, so we can
elide the call if the function body is empty.

(cherry picked from commit 393236a9a8)
This commit is contained in:
Martin Whitaker 2020-12-13 21:42:13 +00:00
parent bfac44a630
commit 1fda3ff23e
1 changed files with 8 additions and 1 deletions

View File

@ -3849,7 +3849,14 @@ NetProc* PCallTask::elaborate_void_function_(Design*des, NetScope*scope,
<< endl;
}
ivl_assert(*this, dscope->elab_stage() >= 3);
// If we haven't already elaborated the function, do so now.
// This allows elaborate_build_call_ to elide the function call
// if the function body is empty.
if (dscope->elab_stage() < 3) {
const PFunction*pfunc = dscope->func_pform();
ivl_assert(*this, pfunc);
pfunc->elaborate(des, dscope);
}
return elaborate_build_call_(des, scope, dscope, 0);
}