Bug 84985 - [7 Regression] ICE in match_reload, at lra-constraints.c:1068
Summary: [7 Regression] ICE in match_reload, at lra-constraints.c:1068
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: inline-asm (show other bugs)
Version: 8.0.1
: P2 normal
Target Milestone: 8.0
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2018-03-20 06:45 UTC by Vegard Nossum
Modified: 2019-11-14 11:22 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 8.0
Known to fail: 7.5.0
Last reconfirmed: 2018-03-20 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vegard Nossum 2018-03-20 06:45:46 UTC
Input:

int main() {
  int a;
  asm("" : "=d"(a) : "0"(a), "0ae"(&a));
}

Output:

$ cc1plus 
 int main()
Analyzing compilation unit
Performing interprocedural optimizations
 <*free_lang_data> <visibility> <build_ssa_passes> <opt_local_passes> <targetclone> <free-fnsummary> <whole-program> <fnsummary> <inline> <free-fnsummary> <single-use> <comdats>Assembling functions:
 <materialize-all-clones> <simdclone> int main()during RTL pass: reload

<stdin>: In function 'int main()':
<stdin>:4:1: internal compiler error: in match_reload, at lra-constraints.c:1068
0x287e277 match_reload
        /home/vegard/git/gcc/gcc/lra-constraints.c:1066
0x28ade79 curr_insn_transform
        /home/vegard/git/gcc/gcc/lra-constraints.c:4335
0x28b93b6 lra_constraints(bool)
        /home/vegard/git/gcc/gcc/lra-constraints.c:4877
0x2829984 lra(_IO_FILE*)
        /home/vegard/git/gcc/gcc/lra.c:2419
0x2608794 do_reload
        /home/vegard/git/gcc/gcc/ira.c:5465
0x2608794 execute
        /home/vegard/git/gcc/gcc/ira.c:5649
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

Version:

GNU C++14 (GCC) version 8.0.1 20180306 (experimental) (x86_64-pc-linux-gnu)

7.3.0 seems to handle it and outputs:

main:
  pushq %rbp
  movq %rsp, %rbp
  movl -4(%rbp), %eax
  leaq -4(%rbp), %rcx
  movl %eax, %edx
  movl %edx, %eax
  movl %eax, -4(%rbp)
  movl $0, %eax
  popq %rbp
  ret

Clang says:

<source>:3:36: error: more than one input constraint matches the same output '0'
  asm("" : "=d"(a) : "0"(a), "0ae"(&a));
                                   ^
<source>:3:26: note: constraint '0' is already present here
  asm("" : "=d"(a) : "0"(a), "0ae"(&a));
                         ^
1 error generated.
Compiler returned: 1
Comment 1 Jakub Jelinek 2018-03-20 08:36:21 UTC
Started with r192719.
Before that it has been rejected with:
pr84985.c: In function ‘main’:
pr84985.c:3:3: error: ‘asm’ operand has impossible constraints
   asm("" : "=d"(a) : "0"(a), "0ae"(&a));
   ^
Only ICEs with -O0, at -O2 it passes.
ICEs even with int a = 1; instead of just int a;, so there is no uninitialized use.
int main() {
  int a = 1;
  asm("" : "=d"(a) : "0"(a), "0r"(&a));
}
ICEs too, but "=r" or "=a" instead does not.
I don't see anything invalid on it, unless it is just "0"(a), "0"(&a) which is of course impossible to reload and is properly diagnosed:
pr84985.c: In function ‘main’:
pr84985.c:3:3: error: inconsistent operand constraints in an ‘asm’
   asm("" : "=d"(a) : "0"(a), "0"(&a));
   ^~~
Comment 2 Martin Liška 2018-03-20 09:00:49 UTC
With -std=c++14 ICE on 4.9.0+.
Comment 3 Vladimir Makarov 2018-03-29 18:29:43 UTC
Author: vmakarov
Date: Thu Mar 29 18:29:12 2018
New Revision: 258961

URL: https://gcc.gnu.org/viewcvs?rev=258961&root=gcc&view=rev
Log:
2018-03-29  Vladimir Makarov  <vmakarov@redhat.com>

	PR inline-asm/84985
	* lra-constraints.c (process_alt_operands): Move setting
	this_alternative_matches below.

2018-03-29  Vladimir Makarov  <vmakarov@redhat.com>

	PR inline-asm/84985
	* gcc.target/i386/pr84985.c: New.


Added:
    trunk/gcc/testsuite/gcc.target/i386/pr84985.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/lra-constraints.c
    trunk/gcc/testsuite/ChangeLog
Comment 4 Jakub Jelinek 2018-10-26 10:12:46 UTC
GCC 6 branch is being closed
Comment 5 Richard Biener 2019-11-14 11:22:42 UTC
Fixed in GCC 8.