[PATCH] Fix PR rtl-optimization/pr60663

Zhenqiang Chen zhenqiang.chen@linaro.org
Wed Mar 26 07:21:00 GMT 2014


Hi,

The patch checks the number of the expected operands in
ASM_OPERANDS_TEMPLATE with the same logic as it in output_asm_insn to
make sure the ASM_OPERANDS are legal.

Bootstrap and no make check regression on X86-64 and ARM chromebook.

OK for trunk?

Thanks!
-Zhenqiang

ChangeLog:
2014-03-26  Zhenqiang Chen  <zhenqiang.chen@linaro.org>

    PR rtl-optimization/pr60663
    * recog.c (check_asm_operands): Check the number of expected operands.

testsuite/ChangeLog:
2014-03-26  Zhenqiang Chen  <zhenqiang.chen@linaro.org>

        * gcc.dg/pr60663: New testcase.

diff --git a/gcc/recog.c b/gcc/recog.c
index f9040dc..65078ad 100644
--- a/gcc/recog.c
+++ b/gcc/recog.c
@@ -135,8 +135,8 @@ check_asm_operands (rtx x)
 {
   int noperands;
   rtx *operands;
-  const char **constraints;
-  int i;
+  const char **constraints, *templ;
+  int i, c;

   if (!asm_labels_ok (x))
     return 0;
@@ -159,7 +159,29 @@ check_asm_operands (rtx x)
   operands = XALLOCAVEC (rtx, noperands);
   constraints = XALLOCAVEC (const char *, noperands);

-  decode_asm_operands (x, operands, NULL, constraints, NULL, NULL);
+  templ = decode_asm_operands (x, operands, NULL, constraints, NULL, NULL);
+  /* The following logic is similar with it in output_asm_insn (final.c).
+     It checks the number of expected operands in ASM_OPERANDS_TEMPLATE.  */
+  if (*templ)
+    {
+      const char* p = templ;
+      while ((c = *p++))
+       {
+         if (c == '%')
+           if (ISDIGIT (*p))
+             {
+               int opnum;
+               char *endptr;
+
+               opnum = strtoul (p, &endptr, 10);
+               if (opnum >= noperands)
+                 return 0;
+
+                p = endptr;
+                c = *p;
+             }
+       }
+    }

   for (i = 0; i < noperands; i++)
     {

diff --git a/gcc/testsuite/gcc.dg/pr60663.c b/gcc/testsuite/gcc.dg/pr60663.c
new file mode 100644
index 0000000..6c01084
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/lp.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options " -O2 " } */
+
+int g (void)
+{
+  unsigned i, j;
+  asm("// %0 %1" : "=r" (i), "=r"(j));
+  return i;
+}



More information about the Gcc-patches mailing list