Fix process reference giving no return statement error (#6767) (#6823)

This commit is contained in:
Krzysztof Bieganski 2025-12-16 00:09:45 +01:00 committed by GitHub
parent 2f9e1fa454
commit 7e67f73844
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 46 additions and 28 deletions

View File

@ -475,6 +475,12 @@ public:
m_usevlSelfRef = false;
if (nodep->isCoroutine()) {
// Sometimes coroutines don't have co_awaits,
// so emit a co_return at the end to avoid compile errors.
puts("co_return;");
}
puts("}\n");
if (nodep->ifdef() != "") puts("#endif // " + nodep->ifdef() + "\n");
}

View File

@ -316,7 +316,6 @@ class TransformForksVisitor final : public VNVisitor {
// STATE
bool m_inClass = false; // Are we in a class?
bool m_beginHasAwaits = false; // Does the current begin have awaits?
bool m_awaitMoved = false; // Has the current function lost awaits?
AstFork* m_forkp = nullptr; // Current fork
AstCFunc* m_funcp = nullptr; // Current function
@ -373,14 +372,7 @@ class TransformForksVisitor final : public VNVisitor {
void visit(AstCFunc* nodep) override {
VL_RESTORER(m_funcp);
m_funcp = nodep;
m_awaitMoved = false;
iterateChildren(nodep);
// cppcheck-suppress knownConditionTrueFalse
if (nodep->isCoroutine() && m_awaitMoved
&& !nodep->stmtsp()->exists([](AstCAwait*) { return true; })) {
// co_return at the end (either that or a co_await is required in a coroutine
nodep->addStmtsp(new AstCStmt{nodep->fileline(), "co_return;"});
}
}
void visit(AstVar* nodep) override {
if (!m_forkp) nodep->user1(true);
@ -459,12 +451,6 @@ class TransformForksVisitor final : public VNVisitor {
newfuncp->setNeedProcess();
newfuncp->addStmtsp(new AstCStmt{flp, "vlProcess->state(VlProcess::FINISHED);"});
}
if (!m_beginHasAwaits) {
// co_return at the end (either that or a co_await is required in a coroutine
newfuncp->addStmtsp(new AstCStmt{flp, "co_return;"});
} else {
m_awaitMoved = true;
}
remapLocals(newfuncp, callp);
}
void visit(AstCAwait* nodep) override {

View File

@ -859,21 +859,14 @@ class TimingControlVisitor final : public VNVisitor {
nodep->addStmtsp(cstmtp);
}
}
AstNode* firstCoStmtp = nullptr; // First co_* statement in the function
nodep->exists([&](AstCAwait* const awaitp) -> bool { return (firstCoStmtp = awaitp); });
if (!firstCoStmtp) {
// It's a coroutine but has no awaits (a class method that overrides/is
// overridden by a suspendable, but doesn't have any awaits itself). Add a
// co_return at the end (either that or a co_await is required in a
// coroutine)
firstCoStmtp = new AstCStmt{nodep->fileline(), "co_return;"};
nodep->addStmtsp(firstCoStmtp);
}
if (nodep->dpiExportImpl()) {
nodep->exists([](AstCAwait* const awaitp) -> bool {
// A DPI-exported coroutine won't be able to block the calling code
// Error on the await node; fall back to the function node
firstCoStmtp->v3warn(E_UNSUPPORTED,
awaitp->v3warn(E_UNSUPPORTED,
"Unsupported: Timing controls inside DPI-exported tasks");
return true;
});
}
}
void visit(AstNodeCCall* nodep) override {

View File

@ -0,0 +1,18 @@
#!/usr/bin/env python3
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2025 by Wilson Snyder. This program is free software; you
# can redistribute it and/or modify it under the terms of either the GNU
# Lesser General Public License Version 3 or the Perl Artistic License
# Version 2.0.
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
import vltest_bootstrap
test.scenarios('simulator')
test.compile(verilator_flags2=["--binary"])
test.execute()
test.passes()

View File

@ -0,0 +1,15 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2025 by Antmicro.
// SPDX-License-Identifier: CC0-1.0
module t;
always something();
function void something();
void'(process::self());
$write("*-* All Finished *-*\n");
$finish;
endfunction
endmodule