Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IRGen] Fix misalignment of conditional invertible requirement counts #73277

Merged
merged 2 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/swift/ABI/GenericContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ class TrailingGenericContextObjects<TargetSelf<Runtime>,
if (!asSelf()->hasConditionalInvertedProtocols())
return 0;

return countBitsUsed(getConditionalInvertedProtocols().rawBits());
return __builtin_popcount(getConditionalInvertedProtocols().rawBits());
}

size_t numTrailingObjects(
Expand Down
7 changes: 7 additions & 0 deletions lib/IRGen/GenMeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1334,6 +1334,13 @@ namespace {
B.addPlaceholderWithSize(IGM.Int16Ty));
}

// The conditional invertible protocol set is alone as a 16 bit slot, so
// an even amount of conditional invertible protocols will cause an uneven
// alignment.
if ((numProtocols & 1) == 0) {
B.addInt16(0);
}

// Emit the generic requirements for the conditional conformance
// to each invertible protocol.
auto nominal = cast<NominalTypeDecl>(Type);
Expand Down