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

fix: let cppgc align to 16 bytes #1677

Merged
merged 2 commits into from
Jan 6, 2025
Merged

fix: let cppgc align to 16 bytes #1677

merged 2 commits into from
Jan 6, 2025

Conversation

devsnek
Copy link
Member

@devsnek devsnek commented Jan 3, 2025

cppgc supports exactly two alignments: 8 byte and 16 byte. We can support this by dispatching to a different base C++ class.

Fixes: #1676

@devsnek devsnek requested a review from lucacasonato January 3, 2025 19:49
Copy link
Member

@lucacasonato lucacasonato left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -343,6 +344,11 @@ pub unsafe fn make_garbage_collected<T: GarbageCollected + 'static>(
heap: &Heap,
obj: T,
) -> Ptr<T> {
const {
// max alignment in cppgc is 16
assert!(std::mem::align_of::<T>() <= 16);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
assert!(std::mem::align_of::<T>() <= 16);
assert!(std::mem::align_of::<T>() <= 16, "cppgc objects have a max alignment of 16");

)
};

assert!(!pointer.is_null());
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
assert!(!pointer.is_null());
// Sanity check: this is already checked by the const assertion above.
debug_assert!(!pointer.is_null());

Copy link
Member

@littledivy littledivy left a comment

Choose a reason for hiding this comment

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

LGTM, needs to be clang-formatted

@devsnek devsnek enabled auto-merge (squash) January 6, 2025 10:02
@devsnek devsnek merged commit 8020991 into main Jan 6, 2025
11 checks passed
@devsnek devsnek deleted the fix-cppgc-align branch January 6, 2025 12:59
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.

cppgc: object alignment is not guaranteed for alignment > 8
3 participants