Bug 106350 - O3 memcpy warning when prepending a length-1 string literal to a constant std::string
Summary: O3 memcpy warning when prepending a length-1 string literal to a constant std...
Status: RESOLVED DUPLICATE of bug 105651
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 13.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic, needs-bisection
Depends on:
Blocks:
 
Reported: 2022-07-19 00:10 UTC by Aly Cerruti
Modified: 2022-07-19 23:10 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Log produced by Compiler Explorer when using gcc (trunk) (626 bytes, text/plain)
2022-07-19 00:10 UTC, Aly Cerruti
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Aly Cerruti 2022-07-19 00:10:57 UTC
Created attachment 53318 [details]
Log produced by Compiler Explorer when using gcc (trunk)

The following code produces a warning under `-std=c++20 -O3 -Wrestrict`:

    #include <string>
    
    std::string memcpy_bug() {
        return "x" + std::string("yz");
    }

(1) If `"x"` is changed to be a string literal of any length other than 1, the warning does not occur
(2) If `std::string("yz")` is pulled out into a variable (i.e. `std::string var("yz");` and `return "x" + var;`) the warning does not occur
(3) If the optimization mode used is O1, O2, or Os, the warning does not occur
(4) If the compiler version is downgraded to GCC 11.3, the warning does not occur

Appending a length-1 literal does not have this issue.

Attached is the log produced by Compiler Explorer on GCC trunk commit c70a48a8f8f6a43b35f783b5672c9a3c0a363c31.

Possibly related to <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105329>. I made the decision to submit this independently due to (2), but I don't doubt that it's likely a duplicate.
Comment 1 Jonathan Wakely 2022-07-19 08:59:40 UTC
I think it is a dup of that one.
Comment 2 Andrew Pinski 2022-07-19 23:10:42 UTC
Dup of bug 105651.

*** This bug has been marked as a duplicate of bug 105651 ***