Skip to content

Conversation

@jkoritzinsky
Copy link
Member

With the refactoring of native type layout information loading to be lazy, we made an assumption that if a type is blittable, the managed size, alignment, and field layout are all equal to the native size, alignment, and field layout. However, our calculation of blittability didn't account for the case of a type with blittable fields having an empty base class. As a result, we were considering these types blittable when they weren't.

Fixes #46643

@jkoritzinsky
Copy link
Member Author

One possible hiccup with this fix is that this blocks creating a Pinned GC Handle to types that match this pattern (since that only allows blittable types).

}

[Fact]
public void SizeOf_TypeWithEmptyBase_ReturnsExpected()
Copy link
Member

Choose a reason for hiding this comment

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

Just to confirm, this test would have failed prior to the above change - correct?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it would have failed since the SizeOf call would return 8.

@ghost
Copy link

ghost commented Jan 7, 2021

Hello @jkoritzinsky!

Because this pull request has the auto-merge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@jkoritzinsky jkoritzinsky merged commit 15be630 into dotnet:master Jan 7, 2021
@jkoritzinsky jkoritzinsky deleted the empty-base-class-fix branch January 7, 2021 02:39
@MichalStrehovsky
Copy link
Member

Crossgen2 also has a definition of IsBlittable that needs updating:

public static bool IsBlittableType(TypeDesc type)

I'm not sure if a mismatch here can result in an issue with R2R, but the added test would definitely not uncover a crossgen2 issue because crossgen2 is not involved in Marshal.SizeOf.

Cc @dotnet/crossgen-contrib

@jkoritzinsky
Copy link
Member Author

/backport to release/5.0

@github-actions
Copy link
Contributor

github-actions bot commented Jan 7, 2021

@MichalStrehovsky
Copy link
Member

Filed #46738 for crossgen2.

@ghost ghost locked as resolved and limited conversation to collaborators Feb 7, 2021
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.

Incorrect marshalling for inherited types when base class has no members

3 participants