dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.27k stars 4.73k forks source link

[mono] iOS FullAOT crashes with condition `method->is_inflated' not met #35674

Closed EgorBo closed 4 years ago

EgorBo commented 4 years ago

((null) error) * Assertion at class.c:1851, condition 'method->is_inflated' not met

(it happens in mono_class_inflate_generic_method_full_checked for Object.GetType)

Simple repro:

using System;
using System.Collections.Generic;

public class Program
{
    public static void Main() {
        Test(1, 2, GetComparer<int>());
    }

    static IComparer<T> GetComparer<T>() where T : IComparable {
        return new AssertComparer<T>();
    }

    static int Test<T>(T low, T high, IComparer<T> comparer) {
        return comparer.Compare(low, high);
    }
}

class AssertComparer<T> : IComparer<T> where T : IComparable
{
    public int Compare(T x, T y) {
        return x.GetType() != y.GetType() ? 1 : 0;
    }
}

Steps to reproduce:

cd src/mono/netcore/sample/iOS/Makefile

# next command should build the whole repo for arm64 and iOS
make runtimepack

# Open 'src/mono/netcore/sample/iOS/Program.cs' and use the repro ^

# generate an XCode project
make bundle USE_LLVM=False

# open Xcode project, deploy to a real device, observe the crash

Many tests crash because of it (some gsharedvt-related issue?)

marek-safar commented 4 years ago

@vargaz could you please look into this, it has now easy repro

vargaz commented 4 years ago

Does this happen with xamarin.ios as well ?

EgorBo commented 4 years ago

@vargaz no, so maybe it's some ENABLE_NETCORE changes or incorrect flags we use for AOT. Looks like iOS AOT is broken in master atm so let me fix it first

EgorBo commented 4 years ago

@vargaz ah, actually everything is OK if you want to try the repro locally, it might complain on

Program.dll.s:127:1: error: file number already allocated
.file 1 "<unknown>"

in Debug mode but if you remove that from Program.dll.s it should build (some new AOTCompiler Task issue)

akoeplinger commented 4 years ago

Xamarin.iOS is hitting this with their NUnit test suites running on .NET6 based mono too, so would be nice to get it fixed to unblock their tests.

vargaz commented 4 years ago

How can I reproduce this with the current setup ?