public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/105823] New: -Wrestrict / -Wstringop-overflow / -Warray-bounds warnings for uninitialized values
@ 2022-06-02 14:02 fiesh at zefix dot tv
  2022-10-23  0:28 ` [Bug c++/105823] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: fiesh at zefix dot tv @ 2022-06-02 14:02 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 105823
           Summary: -Wrestrict / -Wstringop-overflow / -Warray-bounds
                    warnings for uninitialized values
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fiesh at zefix dot tv
  Target Milestone: ---

Some of our code when compiled with enough optimization resulted in weird
-Wrestrict warnings that I think were somehow drawn in through std::string and
then from libstdc++'s char_traits.h.

I tried reducing it and arrived at code which behaves as follows:

% g++ -Wall -Wextra -Wno-nonnull -Wno-stringop-overflow -Wno-array-bounds
-Werror -std=c++20 -O3 -c a.ii

fails because of -Wrestrict, and removing -Wno-stringop-overflow or
-Wno-array-bounds makes these trigger the same warning.  (stringop-overflow is
disabled in char_traits.h which I think is why we hit -Wrestrict instead.)

% g++ -Wall -Wextra -Wno-restrict -Wno-nonnull -Wno-stringop-overflow
-Wno-array-bounds -Werror -std=c++20 -O3 -c a.ii

succeeds.

The warning is:

error: 'void* __builtin_memcpy(void*, const void*, long unsigned int)'
accessing 9223372036854775808 or more bytes at offsets 0 and 0 may overlap up
to 9223372036854775809 bytes at offset -1

The code is:

char aq_ai, bi_bc;
struct ah {
  auto aq(long aj) {
    return __builtin_memcpy(0, &aq_ai, aj);
  }
  long ba_bg;
  void ba() { bi((ba_bg)); }
  ah &bi(long);
};
char *bi_ar;
ah &ah::bi(long bp) {
  if (bp) {
    if (bi_ar >= &bi_bc + bp)
      ;
    else {
      long bt = &bi_bc + bp - bi_ar;
      aq(-bt);
    }
  }
  return *this;
}
void cn() {
  ah container;
  container.ba();
}



Note that changing "bi((ba_bq));" to "bi(ba_bq);", i.e. removing the double
parentheses, makes gcc correctly determine that ba_bq is used uninitialized. 
(Maybe this is the actual bug and assigning -1 to unused values is just what
results in this warning here and is legitimate?)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/105823] -Wrestrict / -Wstringop-overflow / -Warray-bounds warnings for uninitialized values
  2022-06-02 14:02 [Bug c++/105823] New: -Wrestrict / -Wstringop-overflow / -Warray-bounds warnings for uninitialized values fiesh at zefix dot tv
@ 2022-10-23  0:28 ` pinskia at gcc dot gnu.org
  2022-11-29 18:29 ` [Bug tree-optimization/105823] " rguenth at gcc dot gnu.org
  2022-12-27 14:29 ` marxin at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-10-23  0:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note the parentheses changes from a xvalue to an rvalue in C++11+ IIRC which
might be why there is an effect here ...

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug tree-optimization/105823] -Wrestrict / -Wstringop-overflow / -Warray-bounds warnings for uninitialized values
  2022-06-02 14:02 [Bug c++/105823] New: -Wrestrict / -Wstringop-overflow / -Warray-bounds warnings for uninitialized values fiesh at zefix dot tv
  2022-10-23  0:28 ` [Bug c++/105823] " pinskia at gcc dot gnu.org
@ 2022-11-29 18:29 ` rguenth at gcc dot gnu.org
  2022-12-27 14:29 ` marxin at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-11-29 18:29 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |needs-bisection

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
I can now only see the correct

t.C: In member function 'auto ah::aq(long int)':
t.C:4:28: warning: argument 1 null where non-null expected [-Wnonnull]
    4 |     return __builtin_memcpy(0, &aq_ai, aj);
      |            ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
<built-in>: note: in a call to function 'void* __builtin_memcpy(void*, const
void*, long unsigned int)' declared 'nonnull'

not sure what changed it.  If I supply (void *)4 as destination I get

In member function 'auto ah::aq(long int)',
    inlined from 'ah& ah::bi(long int)' at t.C:17:9,
    inlined from 'ah& ah::bi(long int)' at t.C:11:5:
t.C:4:28: warning: 'void* __builtin_memcpy(void*, const void*, long unsigned
int)' specified bound between 9223372036854775808 and 18446744073709551615
exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]
    4 |     return __builtin_memcpy((void *)4, &aq_ai, aj);
      |            ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
In member function 'auto ah::aq(long int)',
    inlined from 'ah& ah::bi(long int)' at t.C:17:9,
    inlined from 'ah& ah::bi(long int)' at t.C:11:5,
    inlined from 'void ah::ba()' at t.C:7:17,
    inlined from 'void cn()' at t.C:24:15:
t.C:4:28: warning: 'void* __builtin_memcpy(void*, const void*, long unsigned
int)' specified bound between 9223372036854775808 and 18446744073709551615
exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]
    4 |     return __builtin_memcpy((void *)4, &aq_ai, aj);
      |            ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~

that resembles what you are seeing I guess.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug tree-optimization/105823] -Wrestrict / -Wstringop-overflow / -Warray-bounds warnings for uninitialized values
  2022-06-02 14:02 [Bug c++/105823] New: -Wrestrict / -Wstringop-overflow / -Warray-bounds warnings for uninitialized values fiesh at zefix dot tv
  2022-10-23  0:28 ` [Bug c++/105823] " pinskia at gcc dot gnu.org
  2022-11-29 18:29 ` [Bug tree-optimization/105823] " rguenth at gcc dot gnu.org
@ 2022-12-27 14:29 ` marxin at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-12-27 14:29 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
                 CC|                            |aldyh at gcc dot gnu.org,
                   |                            |marxin at gcc dot gnu.org
           Keywords|needs-bisection             |
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2022-12-27

--- Comment #3 from Martin Liška <marxin at gcc dot gnu.org> ---
Started with r12-3347-g8af8abfbbace49e6.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-12-27 14:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-02 14:02 [Bug c++/105823] New: -Wrestrict / -Wstringop-overflow / -Warray-bounds warnings for uninitialized values fiesh at zefix dot tv
2022-10-23  0:28 ` [Bug c++/105823] " pinskia at gcc dot gnu.org
2022-11-29 18:29 ` [Bug tree-optimization/105823] " rguenth at gcc dot gnu.org
2022-12-27 14:29 ` marxin at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).