https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116799
Bug ID: 116799 Summary: [14 Regression] Miscompiled code on s390x at -O2 Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: jamessan at jamessan dot com Target Milestone: --- With gcc-14, one of Vim's test_glob2regpat tests started failing on s390x when compiled with -O2. I've minimized Vim's code down to the simple reproduction below. When compile correctly this should output "** -> .*" but instead its showing "** -> $". Bisecting shows that the problem was introduced by https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111294 int printf(const char *, ...); long unsigned int strlen(const char *s); void file_pat_to_reg_pat(const char *pat, char *reg_pat) { const char * pat_end = pat + strlen(pat); while (pat[0] == '*' && pat < pat_end - 1) pat++; const char * endp = pat_end - 1; int add_dollar = 1; if (endp >= pat) { while (endp - pat > 0 && *endp == '*') endp--; add_dollar = 0; } int i = 0; for (const char * p = pat; *p && p <= endp; p++) { switch (*p) { case '*': reg_pat[i++] = '.'; reg_pat[i++] = '*'; while (p[1] == '*') ++p; break; default: reg_pat[i++] = *p; break; } } if (add_dollar) reg_pat[i++] = '$'; reg_pat[i] = '\000'; } int main() { char regpat[7] = {0}; file_pat_to_reg_pat("**", regpat); printf("** -> %s\n", regpat); return 0; }