middle-end/104786 - ICE with asm and VLA
authorRichard Biener <rguenther@suse.de>
Wed, 9 Mar 2022 09:55:49 +0000 (10:55 +0100)
committerRichard Biener <rguenther@suse.de>
Wed, 9 Mar 2022 13:37:02 +0000 (14:37 +0100)
The following fixes an ICE observed with a MEM_REF allows_mem asm
operand referencing a VLA.  The following makes sure to not attempt
to go the temporary creation way when we cannot.

2022-03-09  Richard Biener  <rguenther@suse.de>

PR middle-end/104786
* cfgexpand.cc (expand_asm_stmt): Do not generate a copy
for VLAs without an upper size bound.

* gcc.dg/pr104786.c: New testcase.

gcc/cfgexpand.cc
gcc/testsuite/gcc.dg/pr104786.c [new file with mode: 0644]

index 87536ec..4f99f04 100644 (file)
@@ -3297,7 +3297,9 @@ expand_asm_stmt (gasm *stmt)
                    && GET_MODE (DECL_RTL (val)) != TYPE_MODE (type)))
          || ! allows_reg
          || is_inout
-         || TREE_ADDRESSABLE (type))
+         || TREE_ADDRESSABLE (type)
+         || (!tree_fits_poly_int64_p (TYPE_SIZE (type))
+             && !known_size_p (max_int_size_in_bytes (type))))
        {
          op = expand_expr (val, NULL_RTX, VOIDmode,
                            !allows_reg ? EXPAND_MEMORY : EXPAND_WRITE);
diff --git a/gcc/testsuite/gcc.dg/pr104786.c b/gcc/testsuite/gcc.dg/pr104786.c
new file mode 100644 (file)
index 0000000..3076d23
--- /dev/null
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-options "-std=gnu90" } */
+
+void h(void *di, int num)
+{
+  char (*t)[num] = di;
+  __asm__ ("" : "=X"( *t));
+}