https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114622
Willy Tarreau <w at 1wt dot eu> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |w at 1wt dot eu --- Comment #2 from Willy Tarreau <w at 1wt dot eu> --- Hello, today I got a report of this being -Wstringop-overread being reported on gcc-14.2.1 on impossible code paths at -O0, and I could reproduce it since gcc-12 (only 12.2 tested, 11.4 not affected). The code contains an inline function with __attribute__((alwaysinline)) that takes various key types in arguments to figure how to deal with them. Some key types involve memcmp, others not. There's an extra arg that is used sometimes as the block length, sometimes as anything else. I could simplify the code to the following by removing the inline and caller stuff, and placing the arg and key type directly in local variables. The memcmp line and the commented line can be swapped, either version will report it: #include <string.h> int key_cmp(const void *ptr1, const void *ptr2) { unsigned long opt_arg = 0; int use_arg = 0; if (use_arg) { //return opt_arg < 1 || memcmp(ptr1, ptr2, opt_arg - 1) == 0; return memcmp(ptr1, ptr2, opt_arg - 1); } return 0; } Here it appears obvious to the naked eye that we're not supposed to evaluate memcmp(). I can understand that it's not easy to figure at -O0 but this leaves code in a state where it becomes extremely difficult to shut the warning up, precisely because it incorrectly triggers on impossible code paths. As such I suspect that the most reasonable might be to simply disable this warning at -O0 so that it doesn't trigger on impossible code paths. I tried with pragmas (for a lib where there's little other choices), but on more isolated code I'm afraid I'll rather disable it as unusable otherwise :-/