c and c++ compiler crashes. Testcase: void bar(int); int test(void) { static int test = ((char *)&&l2-(char *)&&l3)+((char *)&&l1-(char *)&&l2); l1: l2: l3: bar(test); return 0; }
better test case int test(void) { static int a = ((char *)&&l2-(char *)&&l3)+((char *)&&l1-(char *)&&l2); l1: l2: l3: return a; }
another testcase: int test(void) { static int a = ((char *)&&l1-(char *)&&l2)-1; l1: l2: return a; }
Confirmed. t.c:10:1: internal compiler error: in gen_reg_rtx, at emit-rtl.c:1059 } ^ 0x95343b gen_reg_rtx(machine_mode) /space/rguenther/src/svn/trunk2/gcc/emit-rtl.c:1059 0xc8a3da maybe_legitimize_operand /space/rguenther/src/svn/trunk2/gcc/optabs.c:8296 0xc8a739 maybe_legitimize_operands(insn_code, unsigned int, unsigned int, expand_operand*) /space/rguenther/src/svn/trunk2/gcc/optabs.c:8369 0xc8a7ca maybe_gen_insn(insn_code, unsigned int, expand_operand*) /space/rguenther/src/svn/trunk2/gcc/optabs.c:8387 0xc79a83 expand_binop_directly /space/rguenther/src/svn/trunk2/gcc/optabs.c:1496 0xc79d0c expand_binop(machine_mode, optab_tag, rtx_def*, rtx_def*, rtx_def*, int, optab_methods) /space/rguenther/src/svn/trunk2/gcc/optabs.c:1566 ... 0x1103344 expand_expr /space/rguenther/src/svn/trunk2/gcc/expr.h:254 0x111098b output_constant /space/rguenther/src/svn/trunk2/gcc/varasm.c:4793 while for example GCC 4.3 says > gcc-4.3 -S t.c -O2 t.c: In function ‘test’: t.c:4: error: initializer element is not computable at load time and > gcc-4.8 -S t.c -O2 t.c:10:1: internal compiler error: output_operand: invalid expression as operand } ^ Please submit a full bug report, with preprocessed source if appropriate. See <http://bugs.opensuse.org/> for instructions. I think the initializers are simply not valid.
But for "static int a = ((char *)&&l1-(char *)&&l2)+1;" GCC is able to emit a valid initializer: .LFE1: .size main, .-main .section .rodata .align 4 .type a.1833, @object .size a.1833, 4 a.1833: .long .L2-.L3+1 And for last testcase the backtrace looks quite different: ./test.c:13:1: internal compiler error: output_operand: invalid expression as operand } ^ 0x7ed77f output_operand_lossage(char const*, ...) ../../src/gcc/final.c:3446 0x7ee045 output_addr_const(_IO_FILE*, rtx_def*) ../../src/gcc/final.c:4035 0x7edfe5 output_addr_const(_IO_FILE*, rtx_def*) ../../src/gcc/final.c:3995 0xd808ee assemble_integer_with_op(char const*, rtx_def*) ../../src/gcc/varasm.c:2743 0xd80956 default_assemble_integer(rtx_def*, unsigned int, int) ../../src/gcc/varasm.c:2759 0xd809d0 assemble_integer(rtx_def*, unsigned int, unsigned int, int) ../../src/gcc/varasm.c:2775 0xd86910 output_constant ../../src/gcc/varasm.c:4795
The gcc-4_8-branch is being closed, re-targeting regressions to 4.9.3.
GCC 4.9.3 has been released.
Investigating.
Author: bernds Date: Thu Jan 21 18:10:03 2016 New Revision: 232689 URL: https://gcc.gnu.org/viewcvs?rev=232689&root=gcc&view=rev Log: Fix PR66178, ICE due to misexpansion of constant expressions involving labels. PR middle-end/66178 * expr.c (expand_expr_real_2) [PLUS_EXPR, MINUS_EXPR]: Don't drop EXPAND_INITIALIZER. * rtl.h (contains_symbolic_reference_p): Declare. * rtlanal.c (contains_symbolic_reference_p): New function. * simplify-rtx.c (simplify_binary_operation_1): Don't turn a subtraction into a NOT if symbolic constants are involved. testsuite/ PR middle-end/66178 gcc.dg/torture/pr66178.c: New test. Added: trunk/gcc/testsuite/gcc.dg/torture/pr66178.c Modified: trunk/gcc/ChangeLog trunk/gcc/expr.c trunk/gcc/rtl.h trunk/gcc/rtlanal.c trunk/gcc/simplify-rtx.c trunk/gcc/testsuite/ChangeLog
Fixed.