Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type preinitialization skips dataflow analysis #97286

Closed
MichalStrehovsky opened this issue Jan 22, 2024 · 1 comment · Fixed by #98318
Closed

Type preinitialization skips dataflow analysis #97286

MichalStrehovsky opened this issue Jan 22, 2024 · 1 comment · Fixed by #98318

Comments

@MichalStrehovsky
Copy link
Member

There's an assignment to a DAM member but since we interpret the cctor instead of executing it, it bypasses the DAM annotations: this program will nullref at runtime.

This is a regression in 9.0.

using System;
using System.Diagnostics.CodeAnalysis;

Preinit.TheType.GetMethod("TheMethod").Invoke(null, []);

class Preinit
{
    [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
    public static Type TheType = typeof(Preinit);

    public static void TheMethod() => Console.WriteLine("Hello");
}
@ghost
Copy link

ghost commented Jan 22, 2024

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Issue Details

There's an assignment to a DAM member but since we interpret the cctor instead of executing it, it bypasses the DAM annotations: this program will nullref at runtime.

This is a regression in 9.0.

using System;
using System.Diagnostics.CodeAnalysis;

Preinit.TheType.GetMethod("TheMethod").Invoke(null, []);

class Preinit
{
    [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
    public static Type TheType = typeof(Preinit);

    public static void TheMethod() => Console.WriteLine("Hello");
}
Author: MichalStrehovsky
Assignees: -
Labels:

area-NativeAOT-coreclr

Milestone: 9.0.0

MichalStrehovsky added a commit to MichalStrehovsky/runtime that referenced this issue Feb 12, 2024
Fixes dotnet#97286.

This just aborts preinitialization if we see dataflow might be involved. It's a conservative fix. We don't have a good spot to communicate dataflow need (e.g. _everything_ from the cctor could potentially be optimized away if the codegen inlines that knowledge).
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Feb 12, 2024
MichalStrehovsky added a commit that referenced this issue Feb 13, 2024
Fixes #97286.

This just aborts preinitialization if we see dataflow might be involved. It's a conservative fix. We don't have a good spot to communicate dataflow need (e.g. _everything_ from the cctor could potentially be optimized away if the codegen inlines that knowledge).
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Feb 13, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Mar 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant