2021-10-18  Uroš Bizjak  <ubiz...@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.
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" } */
+}

Reply via email to