i386: Fix ICE in ix86_print_opreand_address [PR 102761]

Message ID CAFULd4a7H72XTLbX9DyCAdUwyAp47McQ_HY_6uWwTJwZtx+KHg@mail.gmail.com
State Committed
Commit 4abc0c196b10251dc80d0743ba9e8ab3e56c61ed
Headers
Series i386: Fix ICE in ix86_print_opreand_address [PR 102761] |

Commit Message

Uros Bizjak Oct. 18, 2021, 3:06 p.m. UTC
  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.

Boostrapped and regression tested on x86_64-linux-gnu {,-m32}.

Pushed to master, will be backported to other release branches.

Uros.
  

Patch

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 9cc903e826b..5ef1a92a7ce 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.  */
diff --git a/gcc/testsuite/gcc.target/i386/pr102761.c b/gcc/testsuite/gcc.target/i386/pr102761.c
new file mode 100644
index 00000000000..58ff27e4bcc
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr102761.c
@@ -0,0 +1,11 @@ 
+/* PR target/102761 */
+/* { dg-do compile } */
+/* { dg-options "-O1" } */
+
+int foo (void);
+
+void
+bar (void)
+{
+  asm volatile ("%a0" : : "X"(foo () ? 2 : 1)); /* { dg-error "invalid constraints for operand" } */
+}