Skip to content

[release/6.0] JIT: fix bug where a gc struct is not zero initialized - #68050

Merged
carlossanlop merged 1 commit into
dotnet:release/6.0from
AndyAyersMS:Port67825ToRelease6.0
May 4, 2022
Merged

[release/6.0] JIT: fix bug where a gc struct is not zero initialized#68050
carlossanlop merged 1 commit into
dotnet:release/6.0from
AndyAyersMS:Port67825ToRelease6.0

Conversation

@AndyAyersMS

@AndyAyersMSAndyAyersMS commented Apr 14, 2022

Copy link
Copy Markdown
Member

Port of #67825 to release/6.0.

Customer Impact

Reported by RavenDB (see #65694).

This bug can lead to unexpected crashes during GC.

Details

An optimization added in .NET 5 can in some cases lead to the jit reporting an uninitialized struct field as a gc reference.

The attached test case shows a simple app that exhibits this problem. The key components are:

  • a struct type S with one or more ref-class fields
  • a method that explicitly initializes a local s of type S,
    • then updates s via Dictionary.TryGetValue using the .? operator for the dictionary reference,
    • then only accesses the fields of s ifTryGetValue returns true
// "gc" structstructS{objecto;}publicintG(Keyk,Dictionary<Key,S>d){Ss=default;// explicit initializationif(d?.TryGetValue(k,outs)==true&&(s.o!=null)

Testing

Verified with a local RavenDB repro and new test case.

Risk

Low. The IL pattern that leads to this situation is not common. Fix had very minor diffs in SPMI.

@ghostghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Apr 14, 2022
@AndyAyersMS

Copy link
Copy Markdown
MemberAuthor

@BruceForstall PTAL (manual merge)

cc @dotnet/jit-contrib

@BruceForstall
BruceForstall self-requested a review April 14, 2022 20:50
@ghost

Copy link
Copy Markdown

Tagging subscribers to this area: @JulieLeeMSFT
See info in area-owners.md if you want to be subscribed.

Issue Details

Port of #67825 to release/6.0.

Customer Impact

Reported by RavenDB (see #65694)

Details

An optimization added in .NET 5 can in some cases lead to the jit reporting an uninitialized struct field as a gc reference.

Testing

Verified with a local RavenDB repro and new test case.

Risk

Low. The IL pattern that leads to this situation is not common. Fix had very minor diffs in SPMI.

Author:AndyAyersMS
Assignees:-
Labels:

area-CodeGen-coreclr

Milestone:-

@jeffschwMSFTjeffschwMSFT left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approved. We will take this for consideration in 6.0.x

@JulieLeeMSFTJulieLeeMSFT added the Servicing-consider Issue for next servicing release review label Apr 28, 2022
@JulieLeeMSFTJulieLeeMSFT added this to the 6.0.x milestone May 3, 2022
@leecowleecow added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels May 3, 2022
@leecowleecow modified the milestones: 6.0.x, 6.0.6May 3, 2022
@carlossanlop
carlossanlop merged commit f915e1c into dotnet:release/6.0May 4, 2022
@ghostghost locked as resolved and limited conversation to collaborators Jun 4, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIServicing-approvedApproved for servicing release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@AndyAyersMS@jeffschwMSFT@BruceForstall@carlossanlop@leecow@JulieLeeMSFT