Skip to content

Commit ceb7035

Browse files
committed
Ensure that return expressions are properly treated as having side effects
1 parent b67f027 commit ceb7035

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/coreclr/jit/gentree.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -16918,9 +16918,19 @@ bool Compiler::gtNodeHasSideEffects(GenTree* tree, GenTreeFlags flags)
1691816918
// Are there only GTF_CALL side effects remaining? (and no other side effect kinds)
1691916919
if (flags & GTF_CALL)
1692016920
{
16921-
if (tree->OperGet() == GT_CALL)
16921+
GenTree* potentialCall = tree;
16922+
16923+
if (potentialCall->OperIs(GT_RET_EXPR))
16924+
{
16925+
// We need to preserve return expressions where the underlying call
16926+
// has side effects. Otherwise early folding can result in us dropping
16927+
// the call.
16928+
potentialCall = potentialCall->AsRetExpr()->gtInlineCandidate;
16929+
}
16930+
16931+
if (potentialCall->OperIs(GT_CALL))
1692216932
{
16923-
GenTreeCall* const call = tree->AsCall();
16933+
GenTreeCall* const call = potentialCall->AsCall();
1692416934
const bool ignoreExceptions = (flags & GTF_EXCEPT) == 0;
1692516935
const bool ignoreCctors = (flags & GTF_IS_IN_CSE) != 0; // We can CSE helpers that run cctors.
1692616936
if (!call->HasSideEffects(this, ignoreExceptions, ignoreCctors))

0 commit comments

Comments
 (0)