Internals: Add cloneTreePure to prepare for side effect check.

Use cloneTreePure when what is being cloned must be side-effect free.
Use cloneTree when safe to contain side effects (e.g. cloning module).
This commit is contained in:
Wilson Snyder
2023-09-16 22:50:54 -04:00
parent cd1fe64e6c
commit 761adf1cf0
25 changed files with 193 additions and 180 deletions
+3 -3
View File
@@ -283,9 +283,9 @@ private:
// Define what operation will we be doing
AstNodeExpr* operp;
if (VN_IS(nodep, PostSub) || VN_IS(nodep, PreSub)) {
operp = new AstSub{fl, readp->cloneTree(true), newconstp};
operp = new AstSub{fl, readp->cloneTreePure(true), newconstp};
} else {
operp = new AstAdd{fl, readp->cloneTree(true), newconstp};
operp = new AstAdd{fl, readp->cloneTreePure(true), newconstp};
}
if (VN_IS(nodep, PreAdd) || VN_IS(nodep, PreSub)) {
@@ -301,7 +301,7 @@ private:
// PostAdd/PostSub operations
// Assign the original variable to the temporary one
AstAssign* const assignp = new AstAssign{fl, new AstVarRef{fl, varp, VAccess::WRITE},
readp->cloneTree(true)};
readp->cloneTreePure(true)};
insertNextToStmt(nodep, assignp);
// Increment the original variable by one
assignp->addNextHere(new AstAssign{fl, writep, operp});