https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101679
Bug ID: 101679 Summary: duplicate warning offset outside bounds of constant string Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- Only one instance of -Warray-bounds should be reported the access below but GCC issues two. The warning is issued from c_strlen() with the first instance during lowering and the second during (or just before) expansion. The first instance calls suppress_warning(arg, OPT_Warray_bounds) which is checked again before issuing the second instance by calling warning_suppressed_p (arg, OPT_Warray_bounds). The problem is that the first time arg is an ADDR_EXPR but VAR_DECL the second. Stripping the ADDR_EXPR and disabling the warning for its operand is not a solution because it would disable warnings for invalid uses of the same operand in other statements, both in the same function or (for global variables) in others. $ cat a.c && gcc -S -Wall a.c const char s0[0] = { }; char* f (char *d) { return __builtin_strcpy (d, s0); } a.c: In function ‘f’: a.c:5:31: warning: offset ‘0’ outside bounds of constant string [-Warray-bounds] 5 | return __builtin_strcpy (d, s0); | ^~ a.c:1:12: note: ‘s0’ declared here 1 | const char s0[0] = { }; | ^~ a.c:5:10: warning: offset ‘0’ outside bounds of constant string [-Warray-bounds] 5 | return __builtin_strcpy (d, s0); | ^~~~~~~~~~~~~~~~~~~~~~~~ a.c:1:12: note: ‘s0’ declared here 1 | const char s0[0] = { }; | ^~