Beef icon indicating copy to clipboard operation
Beef copied to clipboard

Issue with delegates and pass-by-value on Linux

Open disarray2077 opened this issue 3 years ago • 0 comments

The assertion in the code below fails when:

  • Foo has the uint8[64] padding.
  • Foo has the [CRepr] attribute.
  • Foo is being passed by value to Test.
  • Test is being called through a delegate.
using System;
using System.Diagnostics;

namespace BeefCrashTest;

public static class Program
{
    [CRepr]
    struct Foo
    {
        public char8* bar;
        public uint8[64] padding;
    }

    public static bool Test(Foo f)
    {
        return StringView(f.bar) == "BBBBBBBBBBBBBBB";
    }

    public static void Main()
    {
        Foo f = .() { bar = "BBBBBBBBBBBBBBB" };
        delegate bool(Foo) func = scope => Test;
        Debug.Assert(func(f));
    }
}

Tested with: https://github.com/beefytech/Beef/commit/4c656529556ef2e7f8398be1b6c1d803dea512a6

Edit 05/06/2023: Added more information and simplified repro code.

disarray2077 avatar Nov 24 '22 20:11 disarray2077