Skip to content

Handle blittable byref returns in built-in marshalling - #72433

Merged
jkotas merged 1 commit into
dotnet:mainfrom
jkotas:byref-return
Jul 20, 2022
Merged

Handle blittable byref returns in built-in marshalling#72433
jkotas merged 1 commit into
dotnet:mainfrom
jkotas:byref-return

Conversation

@jkotas

@jkotas jkotas commented Jul 19, 2022

Copy link
Copy Markdown
Member

Fixes #72316

@jkotas
jkotas requested a review from MichalStrehovsky as a code owner July 19, 2022 05:51
@ghost ghost assigned jkotas Jul 19, 2022
&& HasCopyConstructorCustomModifier(parameterIndex, customModifierData))
{
var pointedAtType = type.GetParameterType();
if (!pointedAtType.IsPrimitive && !type.IsEnum && marshallerType != MarshallerType.Field

@jkotas jkotas Jul 19, 2022

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type.IsEnum was always false here since type was a byref.

type = type.GetParameterType();

if (!type.IsPrimitive && type.IsValueType && marshallerType != MarshallerType.Field
if (type.IsValueType && !type.IsPrimitive && !type.IsEnum && !isField

@jkotas jkotas Jul 19, 2022

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to make these conditions consistent and more in sync with CoreCLR logic. This path should be only ever used by managed C++ so it does not matter a whole lot anyway.

{
ILEmitter emitter = _ilCodeStreams.Emitter;

_managedHome = new Home(emitter.NewLocal(ManagedParameterType), ManagedParameterType, isByRef: false);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We just need to create locals of the right type. The default implementation works fine otherwise.

@MichalStrehovsky MichalStrehovsky left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Comment thread src/coreclr/tools/Common/TypeSystem/Interop/IL/MarshalHelpers.cs
@jkotas
jkotas merged commit 2ccf0d5 into dotnet:main Jul 20, 2022
@jkotas
jkotas deleted the byref-return branch July 20, 2022 01:22
@ghost ghost locked as resolved and limited conversation to collaborators Aug 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[NativeAOT] Can't call a function pointer with a ref return value

2 participants