Bug 66178 - [4.9/5/6 Regression] Another label as values ICE in gen_reg_rtx, at emit-rtl.c:1059
Summary: [4.9/5/6 Regression] Another label as values ICE in gen_reg_rtx, at emit-rtl....
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 6.0
: P2 normal
Target Milestone: 4.9.4
Assignee: Bernd Schmidt
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2015-05-16 18:03 UTC by SztfG
Modified: 2016-01-21 18:23 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.3.4
Known to fail:
Last reconfirmed: 2016-01-05 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description SztfG 2015-05-16 18:03:18 UTC
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;
}
Comment 1 SztfG 2015-05-16 18:20:31 UTC
better test case

int test(void)
{
    static int a =  ((char *)&&l2-(char *)&&l3)+((char *)&&l1-(char *)&&l2);
l1:
l2:
l3:
    return a;
}
Comment 2 SztfG 2015-05-16 18:39:02 UTC
another testcase:

int test(void)
{
    static int a =  ((char *)&&l1-(char *)&&l2)-1;
l1:
l2:
    return a;
}
Comment 3 Richard Biener 2015-05-18 07:41:15 UTC
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.
Comment 4 Mikhail Maltsev 2015-05-18 20:31:51 UTC
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
Comment 5 Richard Biener 2015-06-23 08:13:08 UTC
The gcc-4_8-branch is being closed, re-targeting regressions to 4.9.3.
Comment 6 Jakub Jelinek 2015-06-26 19:51:34 UTC
GCC 4.9.3 has been released.
Comment 7 Bernd Schmidt 2016-01-19 14:44:22 UTC
Investigating.
Comment 8 Bernd Schmidt 2016-01-21 18:10:35 UTC
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
Comment 9 Bernd Schmidt 2016-01-21 18:23:17 UTC
Fixed.