Bug 102761 - [10/11/12 Regression] ICE with -O1 and above: in ix86_print_operand_address_as due to %a0 and if_then_else and X constraint
Summary: [10/11/12 Regression] ICE with -O1 and above: in ix86_print_operand_address_a...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 12.0
: P3 normal
Target Milestone: 10.4
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-invalid-code, inline-asm
Depends on:
Blocks:
 
Reported: 2021-10-15 02:57 UTC by Chengnian Sun
Modified: 2021-10-27 19:30 UTC (History)
0 users

See Also:
Host:
Target: x86_64
Build:
Known to work: 9.1.0, 9.4.0
Known to fail: 10.1.0
Last reconfirmed: 2021-10-15 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chengnian Sun 2021-10-15 02:57:47 UTC
$ gcc-trunk -v
Using built-in specs.
COLLECT_GCC=gcc-trunk
COLLECT_LTO_WRAPPER=/scratch/software/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/12.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /tmp/tmp.gzh6IUhxke-gcc-builder/gcc/configure --enable-languages=c,c++,lto --enable-checking-yes --enable-multiarch --prefix=/scratch/software/gcc-trunk --disable-bootstrap
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.0.0 20211014 (experimental) [master -gee9fa8a57] (GCC)

$ cat mutant.c
f() { asm("%a0" : : "X"(tag() ? 2 : 1)); }

$ gcc-trunk -w -O1 mutant.c
during RTL pass: final
mutant.c: In function ‘f’:
mutant.c:1:42: internal compiler error: in ix86_print_operand_address_as, at config/i386/i386.c:13720
    1 | f() { asm("%a0" : : "X"(tag() ? 2 : 1)); }
      |                                          ^
0x83f47a ix86_print_operand_address_as
	/tmp/tmp.gzh6IUhxke-gcc-builder/gcc/gcc/config/i386/i386.c:13720
0xbe46e7 output_address(machine_mode, rtx_def*)
	/tmp/tmp.gzh6IUhxke-gcc-builder/gcc/gcc/final.c:3693
0xbe532e output_asm_insn(char const*, rtx_def**)
	/tmp/tmp.gzh6IUhxke-gcc-builder/gcc/gcc/final.c:3550
0xbe7612 final_scan_insn_1
	/tmp/tmp.gzh6IUhxke-gcc-builder/gcc/gcc/final.c:2690
0xbe789f final_scan_insn(rtx_insn*, _IO_FILE*, int, int, int*)
	/tmp/tmp.gzh6IUhxke-gcc-builder/gcc/gcc/final.c:2940
0xbe7b67 final_1
	/tmp/tmp.gzh6IUhxke-gcc-builder/gcc/gcc/final.c:1997
0xbe8598 rest_of_handle_final
	/tmp/tmp.gzh6IUhxke-gcc-builder/gcc/gcc/final.c:4285
0xbe8598 execute
	/tmp/tmp.gzh6IUhxke-gcc-builder/gcc/gcc/final.c:4363
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.
Comment 1 Andrew Pinski 2021-10-15 03:21:49 UTC
(insn 16 30 20 2 (parallel [
            (asm_operands/v ("%a0") ("") 0 [
                    (if_then_else:SI (ne:SI (reg:SI 0 ax [86])
                            (const_int 0 [0]))
                        (const_int 2 [0x2])
                        (const_int 1 [0x1]))
                ]
                 [
                    (asm_input:SI ("X") /app/example.cpp:1)
                ]
                 [] /app/example.cpp:1)
            (clobber (reg:CC 17 flags))
        ]) "/app/example.cpp":1:7 -1
     (expr_list:REG_DEAD (reg:SI 0 ax [86])
        (expr_list:REG_UNUSED (reg:CC 17 flags)
            (nil))))
Comment 2 Uroš Bizjak 2021-10-15 07:37:52 UTC
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index fb656094e9e..5d019f8e058 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -13921,7 +13921,10 @@ ix86_print_operand_address_as (FILE *file, rtx addr,
 static void
 ix86_print_operand_address (FILE *file, machine_mode /*mode*/, rtx addr)
 {
-  ix86_print_operand_address_as (file, addr, ADDR_SPACE_GENERIC, false);
+  if (this_is_asm_operands && ! address_operand (addr, VOIDmode))
+    output_operand_lossage ("invalid constraints for operand");
+  else
+    ix86_print_operand_address_as (file, addr, ADDR_SPACE_GENERIC, false);
 }
 
 /* Implementation of TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA.  */
Comment 3 GCC Commits 2021-10-18 15:04:40 UTC
The master branch has been updated by Uros Bizjak <uros@gcc.gnu.org>:

https://gcc.gnu.org/g:4abc0c196b10251dc80d0743ba9e8ab3e56c61ed

commit r12-4484-g4abc0c196b10251dc80d0743ba9e8ab3e56c61ed
Author: Uros Bizjak <ubizjak@gmail.com>
Date:   Mon Oct 18 17:03:28 2021 +0200

    i386: Fix ICE in ix86_print_opreand_address [PR 102761]
    
    2021-10-18  Uroš Bizjak  <ubizjak@gmail.com>
    
            PR target/102761
    
    gcc/ChangeLog:
    
            * config/i386/i386.c (ix86_print_operand_address):
            Error out for non-address_operand asm operands.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/i386/pr102761.c: New test.
Comment 4 GCC Commits 2021-10-18 21:01:43 UTC
The releases/gcc-11 branch has been updated by Uros Bizjak <uros@gcc.gnu.org>:

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

commit r11-9171-ge9c3a7243bf7a4db9b0dec44d278e9bf527f3d9b
Author: Uros Bizjak <ubizjak@gmail.com>
Date:   Mon Oct 18 17:03:28 2021 +0200

    i386: Fix ICE in ix86_print_opreand_address [PR 102761]
    
    2021-10-18  Uroš Bizjak  <ubizjak@gmail.com>
    
            PR target/102761
    
    gcc/ChangeLog:
    
            * config/i386/i386.c (ix86_print_operand_address):
            Error out for non-address_operand asm operands.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/i386/pr102761.c: New test.
Comment 5 Uroš Bizjak 2021-10-27 19:27:42 UTC
Not a regression, so let's not backport this too far.

Fixed for gcc-11.3+.
Comment 6 GCC Commits 2021-10-27 19:29:43 UTC
The releases/gcc-10 branch has been updated by Uros Bizjak <uros@gcc.gnu.org>:

https://gcc.gnu.org/g:9644864791547f8ecca23f23a8c6a64cfa79905c

commit r10-10239-g9644864791547f8ecca23f23a8c6a64cfa79905c
Author: Uros Bizjak <ubizjak@gmail.com>
Date:   Mon Oct 18 17:03:28 2021 +0200

    i386: Fix ICE in ix86_print_opreand_address [PR 102761]
    
    2021-10-18  Uroš Bizjak  <ubizjak@gmail.com>
    
            PR target/102761
    
    gcc/ChangeLog:
    
            * config/i386/i386.c (ix86_print_operand_address):
            Error out for non-address_operand asm operands.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/i386/pr102761.c: New test.
Comment 7 Uroš Bizjak 2021-10-27 19:30:45 UTC
(In reply to Uroš Bizjak from comment #5)
> Not a regression, so let's not backport this too far.
> 
> Fixed for gcc-11.3+.

Actually, gcc-10.4+.