https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86622
Bug ID: 86622 Summary: incorrect strlen of array of array plus variable offset Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- As discussed in https://gcc.gnu.org/ml/gcc-patches/2018-07/msg01215.html, GCC emits incorrect code for the following test case: $ cat c.c && gcc c.c && ./a.out static const char a[3][8] = { "1234", "12345", "123456" }; int main () { volatile int i = 1; int n = __builtin_strlen (*(&a[1] + i)); if (n != 6) __builtin_abort (); } Aborted (core dumped) The root cause is the handling of POINTER_PLUS expressions in string_constant(). The original code (before the handling of aggregates was added in r262522) just dealt with string constants. The new code does much more but doesn't get this case right in these cases.