From: Stefan Schulze Frielinghaus <stefa...@gcc.gnu.org>

In case an asm operand is an error node, constraints etc. are still
validated.  Furthermore, all other operands are gimplified, although an
error is returned in the end anyway.  For hard register constraints an
operand is required in order to determine the mode from which the number
of registers follows.  Therefore, I could simply guard hard register
constraints checking or bailing out early.  The former would mean extra
error node checks where we already have a few, and the latter would
reduce the amount of those checks but would also mean that we report
potentially fewer errors during a single run.  Is there any preference?
It seems to me that bailing out as late as possible was desired but I
might be wrong here.
---
 gcc/gimplify.cc                 | 4 ++++
 gcc/testsuite/gcc.dg/pr121391.c | 9 +++++++++
 2 files changed, 13 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/pr121391.c

diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
index ca1fa2189cb..2b790923fa1 100644
--- a/gcc/gimplify.cc
+++ b/gcc/gimplify.cc
@@ -7930,6 +7930,8 @@ gimplify_asm_expr (tree *expr_p, gimple_seq *pre_p, 
gimple_seq *post_p)
       bool ok;
       size_t constraint_len;
 
+      if (TREE_VALUE (link) == error_mark_node)
+       return GS_ERROR;
       link_next = TREE_CHAIN (link);
 
       oconstraints[i]
@@ -8155,6 +8157,8 @@ gimplify_asm_expr (tree *expr_p, gimple_seq *pre_p, 
gimple_seq *post_p)
   int input_num = 0;
   for (link = ASM_INPUTS (expr); link; ++input_num, ++i, link = link_next)
     {
+      if (TREE_VALUE (link) == error_mark_node)
+       return GS_ERROR;
       link_next = TREE_CHAIN (link);
       constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link)));
       reg_info.operand = TREE_VALUE (link);
diff --git a/gcc/testsuite/gcc.dg/pr121391.c b/gcc/testsuite/gcc.dg/pr121391.c
new file mode 100644
index 00000000000..caffa854a9a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr121391.c
@@ -0,0 +1,9 @@
+/* { dg-compile { target aarch64*-*-* arm*-*-* powerpc*-*-* s390*-*-* 
x86_64-*-* } */
+
+/* For the non existing variable we are faced with an error mark node during
+   gimplify_asm_expr().  */
+
+void test (void)
+{
+  __asm__ __volatile__ ("" :: "{2}" (non_existing_var));
+}
-- 
2.49.0

Reply via email to