Bug 2188553 - False g++ stringop-overflow compiler warning
Summary: False g++ stringop-overflow compiler warning
Keywords:
Status: CLOSED UPSTREAM
Alias: None
Product: Fedora
Classification: Fedora
Component: gcc
Version: 41
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: 2025-05-28 15:38 UTC (History)
11 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2025-05-28 15:09:27 UTC
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


Links
System ID Private Priority Status Summary Last Updated
GNU Compiler Collection 117983 0 P3 RESOLVED [12 Regression] -Wstringop-overflow false positive for __builtin_memmove from vector::insert 2025-05-28 15:38:24 UTC

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.

Comment 4 Aoife Moloney 2024-05-07 16:08:38 UTC
This message is a reminder that Fedora Linux 38 is nearing its end of life.
Fedora will stop maintaining and issuing updates for Fedora Linux 38 on 2024-05-21.
It is Fedora's policy to close all bug reports from releases that are no longer
maintained. At that time this bug will be closed as EOL if it remains open with a
'version' of '38'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, change the 'version' 
to a later Fedora Linux version. Note that the version field may be hidden.
Click the "Show advanced fields" button if you do not see it.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora Linux 38 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora Linux, you are encouraged to change the 'version' to a later version
prior to this bug being closed.

Comment 5 Roel van de Kraats 2024-05-08 06:25:14 UTC
Updated 'version' to 39, as it is still seen with:
gcc-c++-13.2.1-7.fc39.x86_64
libstdc++-devel-13.2.1-7.fc39.x86_64

Comment 6 Roel van de Kraats 2024-05-08 17:24:03 UTC
Issue also occurs on F40, with gcc 14:
g++ (GCC) 14.0.1 20240411 (Red Hat 14.0.1-0)
gcc-c++-14.0.1-0.15.fc40.x86_64
libstdc++-devel-14.0.1-0.15.fc40.x86_64

Comment 7 Roel van de Kraats 2024-08-12 14:48:42 UTC
Issue still occurs with gcc 14.2:
g++ (GCC) 14.2.1 20240801 (Red Hat 14.2.1-1)
gcc-14.2.1-1.fc40.x86_64
libstdc++-devel-14.2.1-1.fc40.x86_64

Comment 8 Roel van de Kraats 2025-01-13 09:08:34 UTC
Issue still occurs with gcc 14.2.1 on F41:
g++ (GCC) 14.2.1 20250110 (Red Hat 14.2.1-7)
gcc-14.2.1-7.fc41.x86_64
libstdc++-devel-14.2.1-7.fc41.x86_64

Comment 9 Roel van de Kraats 2025-05-28 15:09:27 UTC
Yay! The problem is solved with gcc 14.3.1. Tested on F41 with:
g++ (GCC) 14.3.1 20250523 (Red Hat 14.3.1-1)

No warning is shown anymore with the same test program and compile command.

And the same with gcc 15.1.1 on F42:
g++ (GCC) 15.1.1 20250521 (Red Hat 15.1.1-2)

Closing ticket.

Comment 10 Jonathan Wakely 2025-05-28 15:38:25 UTC
This was fixed by https://gcc.gnu.org/r14-11508-g4366711d2d66ea upstream


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