Skip to content

Native AOT bad code gen for constrained call #99198

@agocke

Description

@agocke

This looks to be a complicated set of GVMs and direct dispatches to the same interface.

Works on CoreCLR, produces either a null-ref or AV with Native AOT. Core problem is that the call to TryGetNextEntry has two locations in the program: one through a GVM, and one through a constrained invocation on a struct. It appears that the constrained invocation is somehow taking the GVM path, causing an erroneous unbox node to appear that causes memory corruption.
 
project:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net9.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <PublishAot>true</PublishAot>
    <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
    <IlcGenerateMstatFile>true</IlcGenerateMstatFile>
    <IlcGenerateDgmlFile>true</IlcGenerateDgmlFile>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Serde" Version="0.6.0-preview6" />
  </ItemGroup>

</Project>

src:

Console.WriteLine("Hello, World!");

var sampleJson = """
{"latestVersion":{"version":"1.6.8","artifacts":{"linux-x64":"http://localhost:64922/dnvm/dnvm.tar.gz",
"osx-x64":"http://localhost:64922/dnvm/dnvm.tar.gz","win-x64":"http://localhost:64922/dnvm/dnvm.zip"}}}
""";

var release = JsonSerializer.Deserialize<DnvmReleases>(sampleJson);
Console.WriteLine(release);

[GenerateSerde]
public partial record struct DnvmReleases(DnvmReleases.Release LatestVersion)
{
    [GenerateSerde]
    public partial record struct Release(
        string Version,
        Dictionary<string, string> Artifacts);
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions