Fix order of evaluation of function calls in statements (#4375)

This commit is contained in:
Ryszard Rozak
2023-07-21 03:29:11 -04:00
committed by GitHub
parent a6015863d8
commit aa0ef554b3
3 changed files with 64 additions and 7 deletions
+1 -7
View File
@@ -350,7 +350,6 @@ private:
// TYPES
enum InsertMode : uint8_t {
IM_BEFORE, // Pointing at statement ref is in, insert before this
IM_AFTER, // Pointing at last inserted stmt, insert after
IM_WHILE_PRECOND // Pointing to for loop, add to body end
};
using DpiCFuncs = std::map<const string, std::tuple<AstNodeFTask*, std::string, AstCFunc*>>;
@@ -1346,16 +1345,13 @@ private:
AstNode* insertBeforeStmt(AstNode* nodep, AstNode* newp) {
// Return node that must be visited, if any
if (debug() >= 9) nodep->dumpTree("- newstmt: ");
UASSERT_OBJ(m_insStmtp, nodep, "Function not underneath a statement");
UASSERT_OBJ(m_insStmtp, nodep, "Function call not underneath a statement");
AstNode* visitp = nullptr;
if (m_insMode == IM_BEFORE) {
// Add the whole thing before insertAt
UINFO(5, " IM_Before " << m_insStmtp << endl);
if (debug() >= 9) newp->dumpTree("- newfunc: ");
m_insStmtp->addHereThisAsNext(newp);
} else if (m_insMode == IM_AFTER) {
UINFO(5, " IM_After " << m_insStmtp << endl);
m_insStmtp->addNextHere(newp);
} else if (m_insMode == IM_WHILE_PRECOND) {
UINFO(5, " IM_While_Precond " << m_insStmtp << endl);
AstWhile* const whilep = VN_AS(m_insStmtp, While);
@@ -1365,8 +1361,6 @@ private:
} else {
nodep->v3fatalSrc("Unknown InsertMode");
}
m_insMode = IM_AFTER;
m_insStmtp = newp;
return visitp;
}