public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug lto/106020] New: Spurious warnings about stringop overflows only with LTO
@ 2022-06-17 21:05 matt at godbolt dot org
  2022-06-17 21:06 ` [Bug lto/106020] " matt at godbolt dot org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: matt at godbolt dot org @ 2022-06-17 21:05 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106020
           Summary: Spurious warnings about stringop overflows only with
                    LTO
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: lto
          Assignee: unassigned at gcc dot gnu.org
          Reporter: matt at godbolt dot org
                CC: marxin at gcc dot gnu.org
  Target Milestone: ---

When using Howard Hinnant's date library, and GCC 12.1 on x86, and then with
LTO enabled, there are many apparently spurious errors after the read.constprop
pass:

/opt/compiler-explorer/libs/date/v3.0.1/include/date/date.h: In function
'read.constprop':
/opt/compiler-explorer/libs/date/v3.0.1/include/date/date.h:6506:15: note:
destination object 'buf' of size 11
 6506 |         CharT buf[std::numeric_limits<unsigned>::digits10+2u] = {};

It has proven tricky to get a smaller case but https://godbolt.org/z/hPaqz7TY1
demonstrates it with an inline version of date.h - a smaller version that
doesn't inline the date library is https://godbolt.org/z/e75YG6ano and the code
amounts to:

std::chrono::system_clock::time_point parse_datetime(const std::string &sv) {
    std::istringstream ss{sv};
    std::chrono::system_clock::time_point tp;
    ss >> date::parse("%FT%T%Z", tp); // ignoring errors for simplicity
    return tp;
}

(though it has to be linked in a separate TU with LTO enabled to trigger the
issues).

I initially filed this as a bug in the date library itself:
https://github.com/HowardHinnant/date/issues/740 but we now believe this is a
compiler issue.

Compiling with GCC 11 or earlier, or with clang, or without LTO doesn't trigger
these warnings.

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

* [Bug lto/106020] Spurious warnings about stringop overflows only with LTO
  2022-06-17 21:05 [Bug lto/106020] New: Spurious warnings about stringop overflows only with LTO matt at godbolt dot org
@ 2022-06-17 21:06 ` matt at godbolt dot org
  2022-06-17 21:07 ` matt at godbolt dot org
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: matt at godbolt dot org @ 2022-06-17 21:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Matt Godbolt <matt at godbolt dot org> ---
Apologies for the unreduced issue, if I get a chance I'll try and shorten it,
but I hoped someone might recognise what the issue is from just this.

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

* [Bug lto/106020] Spurious warnings about stringop overflows only with LTO
  2022-06-17 21:05 [Bug lto/106020] New: Spurious warnings about stringop overflows only with LTO matt at godbolt dot org
  2022-06-17 21:06 ` [Bug lto/106020] " matt at godbolt dot org
@ 2022-06-17 21:07 ` matt at godbolt dot org
  2022-06-18  5:15 ` [Bug tree-optimization/106020] " pinskia at gcc dot gnu.org
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: matt at godbolt dot org @ 2022-06-17 21:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Matt Godbolt <matt at godbolt dot org> ---
There are many hundreds of similar errors in that example; perhaps this example
is more of a clue:

/opt/compiler-explorer/gcc-12.1.0/include/c++/12.1.0/bits/move.h:205:11:
warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
  205 |       __a = _GLIBCXX_MOVE(__b);

(which seems very suspicious, size 0 inside std::move?)

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

* [Bug tree-optimization/106020] Spurious warnings about stringop overflows only with LTO
  2022-06-17 21:05 [Bug lto/106020] New: Spurious warnings about stringop overflows only with LTO matt at godbolt dot org
  2022-06-17 21:06 ` [Bug lto/106020] " matt at godbolt dot org
  2022-06-17 21:07 ` matt at godbolt dot org
@ 2022-06-18  5:15 ` pinskia at gcc dot gnu.org
  2022-06-18  5:21 ` pinskia at gcc dot gnu.org
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-06-18  5:15 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Can you attach both files instead of the godbolt link?

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

* [Bug tree-optimization/106020] Spurious warnings about stringop overflows only with LTO
  2022-06-17 21:05 [Bug lto/106020] New: Spurious warnings about stringop overflows only with LTO matt at godbolt dot org
                   ` (2 preceding siblings ...)
  2022-06-18  5:15 ` [Bug tree-optimization/106020] " pinskia at gcc dot gnu.org
@ 2022-06-18  5:21 ` pinskia at gcc dot gnu.org
  2022-06-18 13:45 ` matt at godbolt dot org
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-06-18  5:21 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I suspect it is warning on some unreachable code which is not optimized away
until later. Until a full testcase is attached, it is going to be hard. Also it
would be better if not using cmake, just use a makefile if needed or just a
normal shell script to describe how to compile the files (cmake adds so much
stuff to it is sometimes hard to tell if it is doing the right thing).

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

* [Bug tree-optimization/106020] Spurious warnings about stringop overflows only with LTO
  2022-06-17 21:05 [Bug lto/106020] New: Spurious warnings about stringop overflows only with LTO matt at godbolt dot org
                   ` (3 preceding siblings ...)
  2022-06-18  5:21 ` pinskia at gcc dot gnu.org
@ 2022-06-18 13:45 ` matt at godbolt dot org
  2022-06-18 14:02 ` matt at godbolt dot org
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: matt at godbolt dot org @ 2022-06-18 13:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Matt Godbolt <matt at godbolt dot org> ---
Thanks! Understood re: cmake; I wouldn't have picked it but it was the easiest
way to repro something on compiler explorer for Howard at the time. I'm sure we
can get it down to a smaller cast and a shell script.

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

* [Bug tree-optimization/106020] Spurious warnings about stringop overflows only with LTO
  2022-06-17 21:05 [Bug lto/106020] New: Spurious warnings about stringop overflows only with LTO matt at godbolt dot org
                   ` (4 preceding siblings ...)
  2022-06-18 13:45 ` matt at godbolt dot org
@ 2022-06-18 14:02 ` matt at godbolt dot org
  2023-05-18  2:57 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: matt at godbolt dot org @ 2022-06-18 14:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Matt Godbolt <matt at godbolt dot org> ---
I'm afraid to say I've been unable to make a repro case in the short time I had
to try - will get back to this but about to go on vacation (!). That's to say
dumping the files from CE and using:

CXX=/opt/compiler-explorer/gcc-12.1.0/bin/g++
CXXFLAGS=-O3 -flto -fno-fat-lto-objects -fPIC
app: main.o date.o
        $(CXX) $(CXXFLAGS) -o app date.o main.o
main.o:
        $(CXX) $(CXXFLAGS) -o main.o -c main.cpp
date.o:
        $(CXX) $(CXXFLAGS) -o date.o -c date.cpp
clean:
        rm -f app main.o date.o

did _not_ cause the problem, so there's something else going on. Again, will
try and get to this later, but apologies for the "hit and run" bug report :(

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

* [Bug tree-optimization/106020] Spurious warnings about stringop overflows only with LTO
  2022-06-17 21:05 [Bug lto/106020] New: Spurious warnings about stringop overflows only with LTO matt at godbolt dot org
                   ` (5 preceding siblings ...)
  2022-06-18 14:02 ` matt at godbolt dot org
@ 2023-05-18  2:57 ` pinskia at gcc dot gnu.org
  2023-05-18  2:58 ` [Bug tree-optimization/106020] Spurious warnings about stringop overflows with -march=skylake -O3 pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-18  2:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 55107
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55107&action=edit
single file testcase

`-O3 -W -Wall  t.cc -flto  -march=skylake` is enough to invoke the warning.

NOTE -march=skylake is important.
I think this might be a dup of another vectorizer issue with this warning then.

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

* [Bug tree-optimization/106020] Spurious warnings about stringop overflows with -march=skylake -O3
  2022-06-17 21:05 [Bug lto/106020] New: Spurious warnings about stringop overflows only with LTO matt at godbolt dot org
                   ` (6 preceding siblings ...)
  2023-05-18  2:57 ` pinskia at gcc dot gnu.org
@ 2023-05-18  2:58 ` pinskia at gcc dot gnu.org
  2023-05-18  3:29 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-18  2:58 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Spurious warnings about     |Spurious warnings about
                   |stringop overflows only     |stringop overflows with
                   |with LTO                    |-march=skylake -O3

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #7)
> Created attachment 55107 [details]
> single file testcase
> 
> `-O3 -W -Wall  t.cc -flto  -march=skylake` is enough to invoke the warning.
> 
> NOTE -march=skylake is important.
> I think this might be a dup of another vectorizer issue with this warning
> then.

Oh you don't need -flto to invoke the warning either.

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

* [Bug tree-optimization/106020] Spurious warnings about stringop overflows with -march=skylake -O3
  2022-06-17 21:05 [Bug lto/106020] New: Spurious warnings about stringop overflows only with LTO matt at godbolt dot org
                   ` (7 preceding siblings ...)
  2023-05-18  2:58 ` [Bug tree-optimization/106020] Spurious warnings about stringop overflows with -march=skylake -O3 pinskia at gcc dot gnu.org
@ 2023-05-18  3:29 ` pinskia at gcc dot gnu.org
  2023-05-18  3:40 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-18  3:29 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|lto                         |

--- Comment #9 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Reduced much further (still has includes):
```
#include <limits>
#include <algorithm>
void f(const char*);
typedef char CharT;
void read(unsigned u)
{
        CharT buf[std::numeric_limits<unsigned>::digits10+2u] = {};
        CharT* e = buf;
        do
        {
            *e++ = static_cast<CharT>(CharT(u % 10) + CharT{'0'});
            u /= 10;
        } while (u > 0);
        e[0] = 0;
        std::reverse(buf, e);
        f(buf);
}
```
Just compile with `-std=c++20 -O3 -march=skylake` is enough to get the warning.

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

* [Bug tree-optimization/106020] Spurious warnings about stringop overflows with -march=skylake -O3
  2022-06-17 21:05 [Bug lto/106020] New: Spurious warnings about stringop overflows only with LTO matt at godbolt dot org
                   ` (8 preceding siblings ...)
  2023-05-18  3:29 ` pinskia at gcc dot gnu.org
@ 2023-05-18  3:40 ` pinskia at gcc dot gnu.org
  2023-05-18  3:43 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-18  3:40 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #55107|0                           |1
        is obsolete|                            |

--- Comment #10 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 55108
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55108&action=edit
Self contained testcase

Still need `-O3 -march=skylake`

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

* [Bug tree-optimization/106020] Spurious warnings about stringop overflows with -march=skylake -O3
  2022-06-17 21:05 [Bug lto/106020] New: Spurious warnings about stringop overflows only with LTO matt at godbolt dot org
                   ` (9 preceding siblings ...)
  2023-05-18  3:40 ` pinskia at gcc dot gnu.org
@ 2023-05-18  3:43 ` pinskia at gcc dot gnu.org
  2023-05-18  3:58 ` pinskia at gcc dot gnu.org
  2023-05-18 13:23 ` matt at godbolt dot org
  12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-18  3:43 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2023-05-18
     Ever confirmed|0                           |1

--- Comment #11 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed at this point even with a nice reduced testcase for someone to look
into.

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

* [Bug tree-optimization/106020] Spurious warnings about stringop overflows with -march=skylake -O3
  2022-06-17 21:05 [Bug lto/106020] New: Spurious warnings about stringop overflows only with LTO matt at godbolt dot org
                   ` (10 preceding siblings ...)
  2023-05-18  3:43 ` pinskia at gcc dot gnu.org
@ 2023-05-18  3:58 ` pinskia at gcc dot gnu.org
  2023-05-18 13:23 ` matt at godbolt dot org
  12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-18  3:58 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=106074
                 CC|                            |ed at catmur dot uk

--- Comment #12 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 106074 has been marked as a duplicate of this bug. ***

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

* [Bug tree-optimization/106020] Spurious warnings about stringop overflows with -march=skylake -O3
  2022-06-17 21:05 [Bug lto/106020] New: Spurious warnings about stringop overflows only with LTO matt at godbolt dot org
                   ` (11 preceding siblings ...)
  2023-05-18  3:58 ` pinskia at gcc dot gnu.org
@ 2023-05-18 13:23 ` matt at godbolt dot org
  12 siblings, 0 replies; 14+ messages in thread
From: matt at godbolt dot org @ 2023-05-18 13:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #13 from Matt Godbolt <matt at godbolt dot org> ---
Thanks Andrew!

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

end of thread, other threads:[~2023-05-18 13:23 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-17 21:05 [Bug lto/106020] New: Spurious warnings about stringop overflows only with LTO matt at godbolt dot org
2022-06-17 21:06 ` [Bug lto/106020] " matt at godbolt dot org
2022-06-17 21:07 ` matt at godbolt dot org
2022-06-18  5:15 ` [Bug tree-optimization/106020] " pinskia at gcc dot gnu.org
2022-06-18  5:21 ` pinskia at gcc dot gnu.org
2022-06-18 13:45 ` matt at godbolt dot org
2022-06-18 14:02 ` matt at godbolt dot org
2023-05-18  2:57 ` pinskia at gcc dot gnu.org
2023-05-18  2:58 ` [Bug tree-optimization/106020] Spurious warnings about stringop overflows with -march=skylake -O3 pinskia at gcc dot gnu.org
2023-05-18  3:29 ` pinskia at gcc dot gnu.org
2023-05-18  3:40 ` pinskia at gcc dot gnu.org
2023-05-18  3:43 ` pinskia at gcc dot gnu.org
2023-05-18  3:58 ` pinskia at gcc dot gnu.org
2023-05-18 13:23 ` matt at godbolt dot 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).