https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116851

--- Comment #4 from Bil Kleb <Bil.Kleb at NASA dot gov> ---
Created attachment 66329
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=66329&action=edit
GCC 16 -O3 false-positive -Wnonnull from unreachable std::vector assignment
paths with a three-double aggregate.

This appears to be another instance of the same warning-timing problem, now
triggered by a vector of a three-double aggregate rather than a function-local
enum.

The attached reproducer emits two -Werror=nonnull errors with GCC 16.1 (Darwin
r0-b1) and Homebrew GCC 16.2:

    g++ -std=c++17 -O3 -DNDEBUG -Wall -Werror -c reproducer.cpp

It compiles successfully with GCC 15.3 on x86_64 Linux and Apple Clang on
aarch64 Darwin. These comparisons use each compiler's accompanying standard
library; they do not isolate compiler changes from library changes.

On GCC 16.2, both -O2 and -O3 -fno-ipa-cp-clone avoid the diagnostic. Direct
initialization of the four vectors instead of assignment also avoids it.

Comparing GCC 16.2 dumps for this reproducer and the original PR116851 enum
reproducer:

* Both specialize _M_assign_aux for a destination vector whose start, finish,
and end-of-storage pointers are null.
* Both waccess2 dumps contain a warned memmove(nullptr, ...) path requiring the
source pointer difference to be zero AND greater than the element size.
* Both final optimized clones eliminate that null copy.

The aggregate reproducer also produces a second warning on a path requiring
__first - __first to be greater than the element size.

The trigger details differ: the original enum reproducer warns at -O2 but not
-O3 on GCC 16.2, and -fno-ipa-cp-clone does not clear its warning.
Nevertheless, the contradictory path and subsequent elimination appear to match
the mechanism discussed here. Would you consider this the same bug?

Reply via email to