Skip to content

Fix incorrect 64-bit alignment computation for records with a vtable#703

Merged
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-repo-analysis
Jul 12, 2026
Merged

Fix incorrect 64-bit alignment computation for records with a vtable#703
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-repo-analysis

Conversation

@tannergooding

@tannergooding tannergooding commented Jul 12, 2026

Copy link
Copy Markdown
Member

GetTypeSize (in PInvokeGenerator.TypeResolution.cs) computed the 64-bit alignment for a record with a vtable by clamping alignment32 instead of alignment64:

if (alignment64 < 4)
{
    alignment64 = Math.Max(Math.Min(alignment32, 8), 1);   // used alignment32
}

The 32-bit sibling branch just above already uses alignment32; this makes the 64-bit branch use alignment64 as intended.

This is latent in the covered configurations — alignment32 and alignment64 are equal on entry to this branch in the tested cases, so no golden output changes and the full suite passes unchanged. It's still an obvious correctness bug that bites once the two alignments diverge, hence the surgical fix. I couldn't construct a triggering golden-file case, so no test is added; happy to add one if you know a scenario that diverges them here.

Builds clean under TreatWarningsAsErrors.


First in a small series coming out of an analysis pass. The redundant IsVirtual && IsVirtual in HasVtbl I also spotted was already fixed upstream, so it's dropped from this PR.

GetTypeSize computed the 64-bit alignment for a record with a vtable by clamping alignment32 instead of alignment64, so the result was wrong whenever the two values diverged. The 32-bit sibling branch already uses alignment32; make the 64-bit branch use alignment64 as intended.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@tannergooding
tannergooding force-pushed the tannergooding-repo-analysis branch from 270bb46 to 6a33fb1 Compare July 12, 2026 20:13
@tannergooding tannergooding changed the title Fix correctness bugs in struct layout and vtbl detection Fix incorrect 64-bit alignment computation for records with a vtable Jul 12, 2026
@tannergooding
tannergooding merged commit df6df1d into dotnet:main Jul 12, 2026
14 checks passed
@tannergooding
tannergooding deleted the tannergooding-repo-analysis branch July 15, 2026 00:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant