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

            Bug ID: 127277
           Summary: GCC 16.1.1 produces a -Warray-bounds warning with -O3
           Product: gcc
           Version: 16.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: shahzad.malik.muzaffar at cern dot ch
  Target Milestone: ---

GCC 16.1.1 produces a -Warray-bounds warning for a preprocessed C++ source file
(attached) at -O3. The warning is not produced with GCC 14 or GCC15.

The warning also disappears with GCC 16.1.1 when -fno-tree-vrp is added.

Attached: src.cc.i

GCC 16.1.1:

c++ -c -O3 -std=c++23 -march=x86-64-v3 -Wno-attributes -Warray-bounds src.cc.i

This produces:
warning: array subscript
'edm::reftobase::Holder<reco::io_v1::Track,
edm::Ref<std::vector<reco::io_v1::Track> > >[0]'
is partly outside array bounds of 'unsigned char [16]'
[-Warray-bounds]

The diagnostic points to the destructor of Holder<T, REF> and identifies the
allocation as:

new reftobase::IndirectHolder<T>{ ... }

The relevant classes have different sizes: Holder<T, REF> is 24 bytes whereas
IndirectHolder<T> is 16 bytes.

With GCC 16.1.1, adding -fno-tree-vrp makes the warning disappear:

c++ -c -O3 -std=c++23 -march=x86-64-v3 -Wno-attributes -Warray-bounds
-fno-tree-vrp src.cc.i

GCC 15 does not produce this warning when compiling the original source.

Environment:
  OS: AlmaLinux 9
  GCC: 16.1.1
  ARCH: x86_64
  • [Bug c++/127277] New: G... shahzad.malik.muzaffar at cern dot ch via Gcc-bugs

Reply via email to