Skip to content

Fix crossgen2 R2R issues found by static analysis#129495

Open
jtschuster wants to merge 3 commits into
dotnet:mainfrom
jtschuster:jtschuster/fix-crossgen2-r2r-bugs
Open

Fix crossgen2 R2R issues found by static analysis#129495
jtschuster wants to merge 3 commits into
dotnet:mainfrom
jtschuster:jtschuster/fix-crossgen2-r2r-bugs

Conversation

@jtschuster

Copy link
Copy Markdown
Member

Addresses latent bugs in crossgen2/ilc reported in #129042.

  • MutableModule.CompareTo compared _index to itself instead of other._index, so the comparison always returned 0. There are never more than 1 MutableModule in a compilation so this was never exercised.

  • ModuleAndIntValueKey.Equals could dereference a null Module. In practice this was never hit.

  • IsInheritanceChainLayoutFixedInCurrentVersionBubble had a null check after the dereference in its while condition. We can remove the dead check and assert that BaseType is non-null while walking to System.Object.

  • PropertyPseudoDesc/EventPseudoDesc operator== dereferenced operand fields without a null guard; null operands now compare correctly instead of throwing.

  • Removed the unreachable MethodDictionary/TypeDictionary arms of GenericLookupHelper. The only caller never produces those helper IDs, so they don't need to be handled. They now fall through to the existing NotImplementedException default.

Addresses several latent bugs in the ILCompiler.ReadyToRun (crossgen2)
compiler surfaced by PVS-Studio's .NET analysis:

- MutableModule.CompareTo compared _index to itself instead of
  other._index, so the comparison always returned 0.
- ModuleAndIntValueKey.Equals dereferenced Module after a check that
  let "this null, other non-null" fall through, throwing an NRE.
- IsInheritanceChainLayoutFixedInCurrentVersionBubble had a null check
  after the dereference in its while condition; removed the dead check
  and assert that BaseType is non-null while walking to System.Object.
- PropertyPseudoDesc/EventPseudoDesc operator== dereferenced operand
  fields without a null guard; null operands now compare correctly
  instead of throwing.
- Removed the unreachable MethodDictionary/TypeDictionary arms of
  GenericLookupHelper. The sole caller never produces those helper IDs,
  and the TypeDictionary arm would have emitted a fixup the runtime
  dictionary decoder cannot parse. They now fall through to the
  existing NotImplementedException default.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 16, 2026 23:50
@github-actions github-actions Bot added the area-crossgen2-coreclr only use for closed issues label Jun 16, 2026
@jtschuster jtschuster added area-ReadyToRun and removed area-crossgen2-coreclr only use for closed issues labels Jun 16, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes several correctness issues in crossgen2/ILCompiler code paths (primarily latent null-dereferences and an always-0 comparison) and removes unreachable switch cases to align behavior with actual callers.

Changes:

  • Make PropertyPseudoDesc / EventPseudoDesc equality operators null-safe.
  • Fix MutableModule.CompareTo to actually compare against other (instead of itself) and adjust a null-deref in a dictionary key equality implementation.
  • Simplify internal logic/switch handling by removing dead/unreachable code paths and tightening an inheritance-walk loop.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/coreclr/tools/Common/Compiler/PropertyPseudoDesc.cs Make operator== handle null operands safely.
src/coreclr/tools/Common/Compiler/EventPseudoDesc.cs Make operator== handle null operands safely.
src/coreclr/tools/aot/ILCompiler.ReadyToRun/TypeSystem/Mutable/MutableModule.Sorting.cs Fix CompareTo to compare _index with other._index.
src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCodegenCompilation.cs Remove ineffective null check in inheritance-chain loop; assert expected invariant.
src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRunSymbolNodeFactory.cs Remove unreachable MethodDictionary / TypeDictionary arms from GenericLookupHelper.
src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRunCodegenNodeFactory.cs Fix ModuleAndIntValueKey.Equals to avoid dereferencing a null Module.

jtschuster and others added 2 commits June 18, 2026 10:15
- MutableModule.CompareTo: there is only ever one MutableModule per
  build, so assert self-comparison and return 0, dropping the unused
  s_globalIndex/_index bookkeeping.
- ModuleAndIntValueKey.Equals: ModuleDesc has referential identity, so
  compare Module references directly instead of the overcomplicated
  null-guarded Equals call.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 18, 2026 20:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

@jtschuster jtschuster enabled auto-merge (squash) June 18, 2026 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants