https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66880
Bug ID: 66880 Summary: 'error: case label does not reduce to an integer constant' with -fsanitize=shift -std=gnu99. Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: sanitizer Assignee: unassigned at gcc dot gnu.org Reporter: chefmax at gcc dot gnu.org CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org, jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, mpolacek at gcc dot gnu.org, ygribov at gcc dot gnu.org Target Milestone: --- Host: x86_64-pc-linux-gnu Target: x86_64-pc-linux-gnu When compile this testcase with -fsanitize=shift -std=gnu99, such an error happened: $ cat test.c int main (int argc, char **argv) { switch (argc) { case 0xEB << 24: return 1; case 1: return 2; default: return 0; } } $ ~/install/master/bin/gcc -fsanitize=undefined -std=gnu99 test.c -static-libubsan 1.c: In function ‘main’: 1.c:3:5: error: case label does not reduce to an integer constant case 0xEB << 24: return 1; ^ max@max:/tmp$ ~/install/master/bin/gcc -fsanitize=shift -std=gnu99 1.c -static-libubsan 1.c: In function ‘main’: 1.c:3:5: error: case label does not reduce to an integer constant case 0xEB << 24: return 1; ^ $ ~/install/master/bin/gcc -v Using built-in specs. COLLECT_GCC=/home/max/install/master/bin/gcc COLLECT_LTO_WRAPPER=/home/max/install/master/libexec/gcc/x86_64-unknown-linux-gnu/6.0.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: /home/max/workspace/downloads/gcc/configure --enable-multilib --enable-checking --target=x86_64-unknown-linux-gnu --host=x86_64-unknown-linux-gnu --build=x86_64-unknown-linux-gnu --prefix=/home/max/install/master --disable-bootstrap --enable-languages=c,c++ CFLAGS='-g -O0' CXXFLAGS='-g -O0' Thread model: posix gcc version 6.0.0 20150710 (experimental) (GCC) This is caused by this: Breakpoint 1, check_case_value (loc=7699, value=0x7ffff69712a8) at /home/max/workspace/downloads/gcc/gcc/c-family/c-common.c:3620 3620 error_at (loc, "case label does not reduce to an integer constant"); (gdb) call debug_tree(value) <compound_expr 0x7ffff69712a8 type <integer_type 0x7ffff682e7e0 int public SI size <integer_cst 0x7ffff682aee8 constant 32> unit size <integer_cst 0x7ffff682af00 constant 4> align 32 symtab 0 alias set -1 canonical type 0x7ffff682e7e0 precision 32 min <integer_cst 0x7ffff682aea0 -2147483648> max <integer_cst 0x7ffff682aeb8 2147483647> pointer_to_this <pointer_type 0x7ffff6848930>> side-effects arg 0 <call_expr 0x7ffff6833a68 type <void_type 0x7ffff6848150 void VOID align 8 symtab 0 alias set -1 canonical type 0x7ffff6848150 pointer_to_this <pointer_type 0x7ffff68482a0>> side-effects fn <addr_expr 0x7ffff696fd20 type <pointer_type 0x7ffff6987a80> constant arg 0 <function_decl 0x7ffff69202a0 __builtin___ubsan_handle_shift_out_of_bounds>> arg 0 <addr_expr 0x7ffff696fd00 type <pointer_type 0x7ffff69879d8> constant arg 0 <var_decl 0x7ffff6836cf0 *.Lubsan_data0> 1.c:3:15> arg 1 <integer_cst 0x7ffff6970a80 constant 235> arg 2 <integer_cst 0x7ffff6970a68 constant 24>> arg 1 <integer_cst 0x7ffff6970840 type <integer_type 0x7ffff682e7e0 int> constant -352321536> 1.c:3:15> (gdb)