Bug 2188553

Summary: False g++ stringop-overflow compiler warning
Product: [Fedora] Fedora Reporter: Roel van de Kraats <rhbug>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: NEW --- QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 38CC: aoliva, dmalcolm, fweimer, jakub, jlaw, jwakely, mcermak, mpolacek, msebor, nickc, sipoyare
Target Milestone: ---Keywords: Regression
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: ---
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
Compiler output none

Description Roel van de Kraats 2023-04-21 07:05:24 UTC
C++ test program test.cpp:

#include <vector>
void test(std::vector<unsigned char> & dest, std::vector<unsigned char> const& src)
{
    if (not dest.empty()) {
        dest.insert(dest.end(), src.begin(), src.end());
    }
}


Compile with:
g++ -Wall -O2 -o test.cpp.o -c test.cpp

Gives:
...
/usr/include/c++/13/bits/stl_algobase.h:437:30: warning: ‘void* __builtin_memmove(void*, const void*, long unsigned int)’ writing between 2 and 9223372036854775807 bytes into a region of size 0 overflows the destination [-Wstringop-overflow=]
...

Please note that this warning doesn't occur when the if() statement is removed.

g++ (GCC) 13.0.1 20230401 (Red Hat 13.0.1-0)
gcc-c++-13.0.1-0.12.fc38.x86_64
libstdc++-devel-13.0.1-0.12.fc38.x86_64

Reproducible: Always

Steps to Reproduce:
1.See Details
2.
3.
Actual Results:  
Compiler produces a warning (29 lines in total)

Expected Results:  
No warning

g++ 12.2.1 on Fedora 37 doesn't produce this warning

Comment 1 Roel van de Kraats 2023-04-21 07:07:06 UTC
Created attachment 1958759 [details]
Compiler output

Comment 2 Roel van de Kraats 2023-05-01 11:38:38 UTC
Issue still occurs with the latest F38 gcc-c++ package:
g++ (GCC) 13.1.1 20230426 (Red Hat 13.1.1-1)
gcc-c++-13.1.1-1.fc38.x86_64
libstdc++-devel-13.1.1-1.fc38.x86_64

Comment 3 Roel van de Kraats 2023-08-02 15:27:30 UTC
Issue still occurs with gcc 13.2:
g++ (GCC) 13.2.1 20230728 (Red Hat 13.2.1-1)
gcc-c++-13.2.1-1.fc38.x86_64
libstdc++-devel-13.2.1-1.fc38.x86_64

Please let me know if I should report this issue upstream instead.