Bug 2188553 - False g++ stringop-overflow compiler warning
Summary: False g++ stringop-overflow compiler warning
Keywords:
Status: NEW
Alias: None
Product: Fedora
Classification: Fedora
Component: gcc
Version: 38
Hardware: x86_64
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2023-04-21 07:05 UTC by Roel van de Kraats
Modified: 2023-08-02 15:27 UTC (History)
11 users (show)

Fixed In Version:
Doc Type: ---
Doc Text:
Clone Of:
Environment:
Last Closed:
Type: ---
Embargoed:


Attachments (Terms of Use)
Compiler output (5.43 KB, text/plain)
2023-04-21 07:07 UTC, Roel van de Kraats
no flags Details

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.


Note You need to log in before you can comment on or make changes to this bug.