Skip to content

Assert in mini-codegen.c on Mono x86 #60347

Closed
@akoeplinger

Description

@akoeplinger

Run the following code on x86 Mono, e.g. on Android:

float resultF = Add(1.0f, 2.0f);
double resultD = Add(1.0, 2.0);

Console.WriteLine(resultF);
Console.WriteLine(resultD);

static T Add<T>(T left, T right) where T : struct
{
    unchecked
    {
        if      (left is short)  return (T)(ValueType)(short)  ( (short) (ValueType)left + (short) (ValueType)right );
        else if (left is int)    return (T)(ValueType)(int)    ( (int)   (ValueType)left + (int)   (ValueType)right );
        else if (left is long)   return (T)(ValueType)(long)   ( (long)  (ValueType)left + (long)  (ValueType)right );
        else if (left is ushort) return (T)(ValueType)(ushort) ( (ushort)(ValueType)left + (ushort)(ValueType)right );
        else if (left is uint)   return (T)(ValueType)(uint)   ( (uint)  (ValueType)left + (uint)  (ValueType)right );
        else if (left is ulong)  return (T)(ValueType)(ulong)  ( (ulong) (ValueType)left + (ulong) (ValueType)right );
        else if (left is byte)   return (T)(ValueType)(byte)   ( (byte)  (ValueType)left + (byte)  (ValueType)right );
        else if (left is sbyte)  return (T)(ValueType)(sbyte)  ( (sbyte) (ValueType)left + (sbyte) (ValueType)right );
        else if (left is float)  return (T)(ValueType)(float)  ( (float) (ValueType)left + (float) (ValueType)right );
        else if (left is double) return (T)(ValueType)(double) ( (double)(ValueType)left + (double)(ValueType)right );
        else throw new NotImplementedException();
    }
}

It crashes with this runtime assert:

* Assertion at /Users/alexander/dev/runtime/src/mono/mono/mini/mini-codegen.c:2306, condition `sp < 8' not met

I saw that x86 is the only platform where we define MONO_ARCH_USE_FPSTACK to true, that's why we only see it there.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions