https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89699
Bug ID: 89699
Summary: [8 regression] false warning -Wstringop-overflow and
memcmp
Product: gcc
Version: 8.3.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: chantry.xavier at gmail dot com
Target Milestone: ---
Created attachment 45958
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45958&action=edit
reduced test case
I am using gcc 8.3.1 20190228
I got a strange warning on a memcmp call, it looks like gcc is tricked to
believe the length is negative and that it overflows, or something like that ?
Not sure.
With "gcc -O -c memcmp-short.c" :
memcmp-short.c: In function ‘f’:
memcmp-short.c:9:12: warning: ‘memcmp’ specified size between
18446744071562067968 and 18446744073709551615 exceeds maximum object size
9223372036854775807 [-Wstringop-overflow=]
return memcmp(s1, s2, min);
^~~~~~~~~~~~~~~~~~~
This is only triggered with optimizations (-O).
And only with gcc >= 8 according to godbolt.
I think I will use a workaround similar to the one suggested in 89689 :
if (min < 0) { __builtin_unreachable(); }
Cheers !