bash$ cat bug.c int foo(int arr[]) { int i = 2; while (arr[--i]) ; return i; } bash$ gcc -O -ftrapv -c bug.c gcc: Internal error: Segmentation fault (program cc1) bash$ g++ -O -ftrapv -c bug.c g++: Internal error: Segmentation fault (program cc1plus) Compilation succeeds if -O is removed. OTOH, it still crashes with -O -fno-<all -O1 options listed in (gcc)Optimize Options>: bash$ gcc -O -fno-defer-pop -fno-delayed-branch \ -fno-guess-branch-probability -fno-cprop-registers -fno-loop-optimize \ -fno-if-conversion -fno-if-conversion2 -fno-tree-ccp -fno-tree-dce \ -fno-tree-dominator-opts -fno-tree-dse -fno-tree-ter -fno-tree-lrs \ -fno-tree-sra -fno-tree-copyrename -fno-tree-fre -fno-tree-ch \ -fno-merge-constants -fno-omit-frame-pointer \ -ftrapv -c bug.c gcc: Internal error: Segmentation fault (program cc1)
Confirmed. Works with 4.2. We endlessly fold #5 0x08206aa1 in fold_unary (code=NEGATE_EXPR, type=0xb7c5c284, op0=0xb7cd3258) at /home/richard/src/gcc-4_1-branch/gcc/fold-const.c:6876 #6 0x08212e3e in fold_build1_stat (code=NEGATE_EXPR, type=0xb7c5c284, op0=0xb7cd3258) at /home/richard/src/gcc-4_1-branch/gcc/fold-const.c:10475 #7 0x081f8a05 in negate_expr (t=0xb7cd3258) at /home/richard/src/gcc-4_1-branch/gcc/fold-const.c:1167 #8 0x08206aa1 in fold_unary (code=NEGATE_EXPR, type=0xb7c5c284, op0=0xb7cd3258) at /home/richard/src/gcc-4_1-branch/gcc/fold-const.c:6876 #9 0x08212e3e in fold_build1_stat (code=NEGATE_EXPR, type=0xb7c5c284, op0=0xb7cd3258) at /home/richard/src/gcc-4_1-branch/gcc/fold-const.c:10475 #10 0x081f8a05 in negate_expr (t=0xb7cd3258) ... #28 0x081f8a05 in negate_expr (t=0xb7cd3258) at /home/richard/src/gcc-4_1-branch/gcc/fold-const.c:1167 1167 tree temp = fold_convert (ntype, TREE_OPERAND (t, 0)); (gdb) call debug_generic_expr (t) -07fffffff which has overflowed. #29 0x08206aa1 in fold_unary (code=NEGATE_EXPR, type=0xb7c5c284, op0=0xb7cd3258) at /home/richard/src/gcc-4_1-branch/gcc/fold-const.c:6876 #30 0x08212e3e in fold_build1_stat (code=NEGATE_EXPR, type=0xb7c5c284, op0=0xb7cd3258) at /home/richard/src/gcc-4_1-branch/gcc/fold-const.c:10475 #31 0x081f8a05 in negate_expr (t=0xb7cd3258) at /home/richard/src/gcc-4_1-branch/gcc/fold-const.c:1167 #32 0x0820cb87 in fold_binary (code=CEIL_DIV_EXPR, type=0xb7c5c284, op0=0xb7cd3258, op1=0xb7c4da50) at /home/richard/src/gcc-4_1-branch/gcc/fold-const.c:8420 #33 0x08212e8e in fold_build2_stat (code=CEIL_DIV_EXPR, type=0xb7c5c284, op0=0xb7cd3258, op1=0xb7c4da50) at /home/richard/src/gcc-4_1-branch/gcc/fold-const.c:10521 #34 0x080fe243 in infer_loop_bounds_from_undefined (loop=0x86a5310) #32 0x0820cb87 in fold_binary (code=CEIL_DIV_EXPR, type=0xb7c5c284, op0=0xb7cd3258, op1=0xb7c4da50) at /home/richard/src/gcc-4_1-branch/gcc/fold-const.c:8420 8420 case ROUND_DIV_EXPR: (gdb) call debug_generic_expr (op0) -07fffffff (gdb) call debug_generic_expr (op1) -1
Closing 4.1 branch.