https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128003
Bug ID: 128003
Summary: wrong code with -fwrapv for a switch on _BitInt(128)
lowered to a jump table
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
volatile int v;
__attribute__((noipa)) void f(_BitInt(128) x) {
switch (x) {
case 10: v = 10; break;
case 11: v = 11; break;
case 12: v = 12; break;
case 13: v = 13; break;
case 14: v = 14; break;
case 15: v = 15; break;
case 16: v = 16; break;
case 17: v = 17; break;
default: v = -1; break;
}
}
int main(void) {
f((_BitInt(128))11 - ((_BitInt(128))1 << 64));
if (v != -1)
__builtin_abort();
}
godbolt: https://godbolt.org/z/o4PG1sW31
The argument 11 - 2^64 matches none of the case labels, so f should take the
default label and the program should exit normally, as it does at -O0 -fwrapv
and at -O2 without -fwrapv. With -fwrapv at -O1, -O2, -O3 or -Os, f takes case
11 and the program aborts. -fno-jump-tables or -fdisable-tree-switchlower1
avoids it.
Disclaimer: This test case was generated by a fuzzer, and the report was
written with LLM assistance.