Bug 84683 - [7 Regression] internal compiler error: in move_for_stack_reg, at reg-stack.c:1173
Summary: [7 Regression] internal compiler error: in move_for_stack_reg, at reg-stack.c...
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: Jakub Jelinek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-03-02 21:15 UTC by Vegard Nossum
Modified: 2022-09-13 18:50 UTC (History)
1 user (show)

See Also:
Host:
Target: x86_64-*-*, i?86-*-*
Build:
Known to work: 8.1.0
Known to fail: 7.5.0
Last reconfirmed: 2018-03-03 00:00:00


Attachments
gcc8-pr84683.patch (649 bytes, patch)
2018-03-05 16:48 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Vegard Nossum 2018-03-02 21:15:51 UTC
Input:

void a(float b, double c) {
  for (int e = 0; e < 2; e++) {
    asm volatile ("" : "+f" (c));
    asm ("" : "+rm" (c = b));
  }
}

Output:

$ xgcc -x c++ -S -Wall -fpermissive -O3 -
<stdin>: In function 'void a(float, double)':
<stdin>:3:34: error: output constraint 0 must specify a single register
during RTL pass: stack
<stdin>:6:1: internal compiler error: in move_for_stack_reg, at reg-stack.c:1173
0x2d49787 move_for_stack_reg
        /home/vegard/git/gcc/gcc/reg-stack.c:1173
0x2d5c1fa subst_stack_regs
        /home/vegard/git/gcc/gcc/reg-stack.c:2437
0x2d5ced7 convert_regs_1
        /home/vegard/git/gcc/gcc/reg-stack.c:3062
0x2d5ced7 convert_regs_2
        /home/vegard/git/gcc/gcc/reg-stack.c:3197
0x2d64844 convert_regs
        /home/vegard/git/gcc/gcc/reg-stack.c:3232
0x2d64844 reg_to_stack
        /home/vegard/git/gcc/gcc/reg-stack.c:3357
0x2d64844 rest_of_handle_stack_regs
        /home/vegard/git/gcc/gcc/reg-stack.c:3412
0x2d64844 execute
        /home/vegard/git/gcc/gcc/reg-stack.c:3443

$ xgcc --version
xgcc (GCC) 8.0.1 20180301 (experimental)

Built from git c435a9e730c6e8f10da09d58b4fc9aaeb401b0d5 (r258097).

4.8.5 seems to produce this:

<source>: In function 'void a(float, double)':
<source>:3:33: error: output constraint 0 must specify a single register
     asm volatile ("" : "+f" (c));
                                 ^
<source>:3:33: error: output constraint 0 must specify a single register
<source>:3:33: error: implicitly popped regs must be grouped at top of stack
Compiler returned: 1

Test case was minimised by C-Reduce.
Comment 1 Jakub Jelinek 2018-03-03 12:29:23 UTC
Started with r204212.
Comment 2 Jakub Jelinek 2018-03-05 16:48:19 UTC
Created attachment 43569 [details]
gcc8-pr84683.patch

Untested fix.
Comment 3 Jakub Jelinek 2018-03-06 09:24:43 UTC
Author: jakub
Date: Tue Mar  6 09:23:36 2018
New Revision: 258273

URL: https://gcc.gnu.org/viewcvs?rev=258273&root=gcc&view=rev
Log:
	PR inline-asm/84683
	* reg-stack.c (move_for_stack_reg): If any_malformed_asm, avoid
	assertion failure.

	* g++.dg/ext/pr84683.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/ext/pr84683.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/reg-stack.c
    trunk/gcc/testsuite/ChangeLog
Comment 4 Jakub Jelinek 2018-03-06 11:21:07 UTC
Fixed for 8.1+ so far.
Comment 5 Jakub Jelinek 2018-10-26 10:09:14 UTC
GCC 6 branch is being closed
Comment 6 Richard Biener 2019-11-14 11:16:27 UTC
Fixed in GCC 8.
Comment 7 GCC Commits 2022-09-13 18:50:40 UTC
The master branch has been updated by Roger Sayle <sayle@gcc.gnu.org>:

https://gcc.gnu.org/g:ff85f0afc7d5684378944f88a9bc9b931034788b

commit r13-2653-gff85f0afc7d5684378944f88a9bc9b931034788b
Author: Roger Sayle <roger@nextmovesoftware.com>
Date:   Tue Sep 13 19:49:20 2022 +0100

    PR target/106877: Robustify reg-stack to malformed asm.
    
    This patch resolves PR target/106877 an ICE-on-invalid inline-asm
    regression.  An innocent upstream change means that the test case
    from PR inline-asm/84683 now hits a different assert in reg-stack.cc's
    move_for_stack_reg.  Fixed by duplicating Jakub's solution to PR 84683
    https://gcc.gnu.org/pipermail/gcc-patches/2018-March/495193.html at
    this second (similar) gcc_assert.
    
    2022-09-13  Roger Sayle  <roger@nextmovesoftware.com>
    
    gcc/ChangeLog
            PR target/106877
            * reg-stack.cc (move_for_stack_reg): Check for any_malformed_asm
            in gcc_assert.
    
    gcc/testsuite/ChangeLog
            PR target/106877
            * g++.dg/ext/pr106877.C: New test case.