Skip to content

Suppress GCC false positive -Wstringop-overflow in enqueue_bulk (#456) - #457

Open
AnmolS05 wants to merge 1 commit into
cameron314:masterfrom
AnmolS05:fix/gcc-stringop-overflow-false-positive-456
Open

AnmolS05 wants to merge 1 commit into
cameron314:masterfrom
AnmolS05:fix/gcc-stringop-overflow-false-positive-456

Conversation

@AnmolS05

@AnmolS05 AnmolS05 commented Oct 5, 2026

Copy link
Copy Markdown

Fixes #456.

Problem

GCC 14, 15, and 16 emit a spurious -Wstringop-overflow diagnostic warning under -O2 and -O3 when enqueue_bulk is called with an explicit producer token and an iterator materializing move-only elements upon dereference. Because -Wstringop-overflow is enabled by default under -O2, -Werror builds fail outright.

The warning originates from this->tailIndex.load() inside ExplicitProducer::enqueue_bulk, reached via inner_enqueue_bulk. GCC's value range analysis considers an inlined path where token.producer is null, concluding that the atomic load operates on address zero.

Solution

As discussed and approved in #456, this PR adds a localized diagnostic pragma around the static_cast<ExplicitProducer*>(token.producer)->... call in inner_enqueue_bulk, guarded by #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 7.

  • No codegen change: Purely diagnostic suppression with zero runtime overhead.
  • Compiler compatibility: Guarded by __GNUC__ >= 7 to avoid -Wpragmas warnings on older GCC versions (GCC 4.8 – 6) where -Wstringop-overflow does not exist.
  • Safety: Avoids optimizer assumptions like __builtin_unreachable().

Testing

  • Reproduced and verified fix on MinGW GCC 15.2.0 with -O2 -std=c++17 -Wall -Wextra -Werror (diagnostic completely silenced).
  • Added unit test enqueue_bulk_producer_token_generating_iterator in tests/unittests/unittests.cpp.
  • Executed unit test suite (8 iterations): 46 / 46 unit tests passed.
  • Executed fuzz test suite under -O2: all randomized tests passed.

…ron314#456)

GCC 14+ emits a spurious -Wstringop-overflow diagnostic under -O2/-O3
when enqueue_bulk is called with an explicit producer token and an iterator
materializing move-only elements on dereference.

Wrap the static_cast in inner_enqueue_bulk with a localized diagnostic pragma
(guarded by __GNUC__ >= 7) as endorsed in issue cameron314#456. Add a unit test
verifying bulk enqueuing with an explicit producer token, move-only objects,
and a generating iterator.
Copilot AI balanced review requested due to automatic review settings October 5, 2026 06:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

-Wstringop-overflow false positive in enqueue_bulk with a producer token (GCC 14-16, -O2+)

2 participants