Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

NativeAOT: bug on long comparison #1214

Closed
Labels
area-NativeAOT-coreclr.NET runtime optimized for ahead of time compilation
@dellamonica

Description

@dellamonica

Here's a small project that reproduces the issue:

<ProjectSdk="Microsoft.NET.Sdk">  <PropertyGroup>    <OutputType>Exe</OutputType>    <TargetFramework>net5.0</TargetFramework>  </PropertyGroup>    <PropertyGroup>    <Optimize>true</Optimize>    <RootAllApplicationAssemblies>false</RootAllApplicationAssemblies>    <IlcInvariantGlobalization>true</IlcInvariantGlobalization>    <IlcGenerateCompleteTypeMetadata>false</IlcGenerateCompleteTypeMetadata>    <IlcDisableReflection>true</IlcDisableReflection>    <IlcOptimizationPreference>Speed</IlcOptimizationPreference>  </PropertyGroup>  <ItemGroup>    <PackageReferenceInclude="Microsoft.DotNet.ILCompiler"Version="6.0.0-*" />  </ItemGroup></Project>
usingSystem;namespaceBugNativeAOT{internalclassProgram{privatereadonlystructSize{publicintWidth{get;}publicintHeight{get;}publiclongArea=>Width*(long)Height;publicSize(intwidth,intheight){Width=width;Height=height;}}privatesealedclassBug{publicBug(Sizes){S=s;}publicSizeS{get;}}privatestaticvoidMain(string[]args){vart=newBug(newSize(0,0));if(t.S.Area==0L){Console.WriteLine("Expected: == operator");}else{Console.WriteLine("UNEXPECTED: == operator");Console.WriteLine($"Area value ={t.S.Area}");}if(0L.Equals(t.S.Area)){Console.WriteLine("Expected: long.Equals");}else{Console.WriteLine("UNEXPECTED: == long.Equals");Console.WriteLine($"Area value ={t.S.Area}");}if(((object)t.S.Area).Equals(0L)){Console.WriteLine("Expected: object.Equals boxed");}else{Console.WriteLine("UNEXPECTED: == object.Equals boxed");Console.WriteLine($"Area value ={t.S.Area}");}}}}

The output is

UNEXPECTED: == operatorArea value = 0UNEXPECTED: == long.EqualsArea value = 0Expected: object.Equals boxed

I haven't tested other types and I'm not sure the example is exactly minimal, but it reproduces the bug I found when using something similar.

NOTE: if I disable the optimizations in the .csproj, the program outputs the expected results.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-NativeAOT-coreclr.NET runtime optimized for ahead of time compilation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp