Skip to content

Honor Over-Aligned Element Types in ProducerConsumerQueue - #2733

Open
colalb1 wants to merge 5 commits into
meta:mainfrom
colalb1:fix-pcq-overaligned-storage
Open

colalb1 wants to merge 5 commits into
meta:mainfrom
colalb1:fix-pcq-overaligned-storage

Conversation

@colalb1

@colalb1 colalb1 commented Nov 3, 2026 •

Copy link
Copy Markdown

ProducerConsumerQueue allocates its ring with std::malloc, which only guarantees alignof(std::max_align_t). A T with a stricter alignas is then constructed on misaligned storage. This is undefined behavior, may crash: an alignas(32) __m256d struct built with -mavx2 segfaults on an aligned vmovapd store.

Over-aligned T now uses folly::operator_new and folly::operator_delete with std::align_val_t. Other types keep std::malloc and std::free. There is no change to the public API or object layout. Generated code for ProducerConsumerQueue<long> is identical before and after.

@meta-cla meta-cla Bot added the CLA Signed label Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant