Skip to content

PInvokeGenerator ignores calling convention attribute on function pointer #237

@DCNick3

Description

@DCNick3

Repro:
test.cpp:

struct test {
    void (__stdcall* test_cb)(void);
};

Command line (on arch linux): dotnet run -r ubuntu.18.04-x64 -f net5.0 -- -a -target i386-pc-win32 -n test -f test.cpp -o test.cs

Produced output:

namespace test
{
    public unsafe partial struct test
    {
        [NativeTypeName("void (*)() __attribute__((stdcall))")]
        public delegate* unmanaged[Cdecl]<void> test_cb;
    }
}

Expected output:

namespace test
{
    public unsafe partial struct test
    {
        [NativeTypeName("void (*)() __attribute__((stdcall))")]
        public delegate* unmanaged[Stdcall]<void> test_cb;
    }
}

(Notice the ignored calling convention)

I found a codepath where this information was discarded:

https://github.com/microsoft/ClangSharp/blob/73da2e7a8f75a2b789620b0882a55dd66b6ee05c/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs#L1625-L1628

This clause unwraps AttributedType and calls the same function for attributedType.ModifiedType.

attributedType.Handle.FunctionTypeCallingConv is CXCallingConv_X86StdCall, but ModifiedType does not have this information and attributedType.ModifiedType.Handle.FunctionTypeCallingConv is CXCallingConv_C

win32metadata evades this by having Winapi as a default calling convention (--with-callconv *=Winapi) and seemingly all callbacks using this calling convention.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions