Repository navigation
JIT: Make GenTree::Compare more conservative around several node types - #135363
Merged
Merged
Conversation
Post-morph head/tail merge could merge statements that differ only in the field sequence of an offset constant, e.g. IND(ADD(obj, 0x38 Fseq[A])) and IND(ADD(obj, 0x38 Fseq[B])) coming from different GDV arms. The surviving tree's field (and hence its type) then applied to all paths, which allowed an isinst to be folded away incorrectly. Fixes dotnet#135350 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 6d240d47-05da-4cbb-8dfd-f64b265cd3e1
|
Azure Pipelines: Successfully started running 5 pipeline(s). 11 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
* CNS_INT: also compare the handle kind and the compile-time handle. * Relops: compare GTF_RELOP_NAN_UN (ordered vs unordered). * All indir-like nodes (ARR_LENGTH, MDARR_*, NULLCHECK, atomics, CMPXCHG): compare GTF_IND_FLAGS, which includes the path-dependent GTF_IND_NONFAULTING. * ARR_ADDR: compare the path-dependent GTF_ARR_ADDR_NONNULL. * BOX: compare the upstream def/copy statements. * Treat unexpected ExOps as unequal in release builds. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 6d240d47-05da-4cbb-8dfd-f64b265cd3e1
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The reported miscompile lacks a focused regression test.
1 open finding
What changed in this PR
Fixes unsafe JIT tree equality that could cause head/tail merging to discard path-specific semantics.
Changes:
- Compares constant metadata, field sequences, and handles.
- Compares semantic relop, indirection, array-address, and box state.
- Conservatively rejects unexpected extended operators.
| File | Description |
|---|---|
src/coreclr/jit/gentree.cpp |
Strengthens GenTree::Compare correctness. |
🧠 Review effort: Balanced
Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.
Member
Author
|
PTAL @adamperlin @dotnet/jit-contrib This just makes GenTree::Compare more conservative when comparing trees. The actual bug is for GT_CNS_INT, but I fixed a few more issues along the road. |
adamperlin
reviewed
Oct 8, 2026
adamperlin
approved these changes
Oct 8, 2026
Member
Author
|
/ba-g unrelated smpt failures |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #135350
GenTree::Compareignored the field sequence onGT_CNS_INT, so post-morph head/tail merge could merge statements that differ only in which field an offset constant refers to. In the Roslyn case, the two arms of a GDV overContainingTypeended with:Both fields happen to live at offset
0x38, so the statements compared equal and the guarded arm's copy was kept for all paths._containingTypeis typed as a sealedNamedTypeSymbolsubclass, so theisinstwas later folded away, andContainingType != nullbecame_containingSymbol != nullfor every object.The fix makes
GT_CNS_INTcomparison require matching field sequences, mirroring the existinggtFldHndcheck forGT_FIELD_ADDR. No SPMI diffs.While here,
GenTree::Comparealso now compares a few other correctness-relevant fields it used to ignore:GT_CNS_INT: handle kind and compile-time handle.GTF_RELOP_NAN_UN(ordered vs unordered).ARR_LENGTH,MDARR_*,NULLCHECK, atomics,CMPXCHG, not justIND/BLK/stores):GTF_IND_FLAGS, which includes the path-dependentGTF_IND_NONFAULTING.GT_ARR_ADDR: the path-dependentGTF_ARR_ADDR_NONNULL.GT_BOX: the upstream def/copy statements.Almost no diffs