https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127966
Bug ID: 127966
Summary: [15/16/17 Regression] wrong code at -O1 and above with
a loop over string literal bytes >= 0x80
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: kyuwoncho18 at gmail dot com
Target Milestone: ---
Target: x86_64-pc-linux-gnu
int main(void)
{
int i = 0;
while (((unsigned char *)"\x80\x80")[i] == 128)
i++;
return i;
}
godbolt: https://godbolt.org/z/oM5Wsxbd8
With -O0, GCC 14 or clang -O3, it returns 2, but with GCC -O1 it returns 1 and
with -O2/-O3/-Os it returns 0. GCC 15.1 and later, including current trunk, are
affected; -funsigned-char does not change the result.
Disclaimer: This test case was generated by a fuzzer, and the report was
written with LLM assistance.