]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR middle-end/67653 (ICE on valid code on x86_64-linux-gnu: verify_gimpl...
authorJakub Jelinek <jakub@redhat.com>
Thu, 11 Feb 2016 09:23:58 +0000 (10:23 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 11 Feb 2016 09:23:58 +0000 (10:23 +0100)
Backported from mainline
2016-01-21  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/67653
* gimplify.c (gimplify_asm_expr): Warn if it is too late to
attempt to mark memory input operand addressable and
call prepare_gimple_addressable in that case.  Don't adjust
input_location for diagnostics, use error_at instead.

* c-c++-common/pr67653.c: New test.
* gcc.dg/torture/pr29119.c: Add dg-warning.

From-SVN: r233332

gcc/ChangeLog
gcc/gimplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/pr67653.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/pr29119.c

index 90697adea800bccdbb42648fb74f545b113f7fa6..f32e2e74a4c2a383c7689a5ef3480a639d89ce31 100644 (file)
@@ -1,6 +1,14 @@
 2016-02-11  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2016-01-21  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/67653
+       * gimplify.c (gimplify_asm_expr): Warn if it is too late to
+       attempt to mark memory input operand addressable and
+       call prepare_gimple_addressable in that case.  Don't adjust
+       input_location for diagnostics, use error_at instead.
+
        2016-01-19  Jakub Jelinek  <jakub@redhat.com>
 
        PR rtl-optimization/68955
index 89e7334e8cd79dbd6310a810baa58ea7462e6ab7..84d318bf19a5c6614e775afb255771d62035cddf 100644 (file)
@@ -5062,12 +5062,38 @@ gimplify_asm_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p)
            TREE_VALUE (link) = error_mark_node;
          tret = gimplify_expr (&TREE_VALUE (link), pre_p, post_p,
                                is_gimple_lvalue, fb_lvalue | fb_mayfail);
+         if (tret != GS_ERROR)
+           {
+             /* Unlike output operands, memory inputs are not guaranteed
+                to be lvalues by the FE, and while the expressions are
+                marked addressable there, if it is e.g. a statement
+                expression, temporaries in it might not end up being
+                addressable.  They might be already used in the IL and thus
+                it is too late to make them addressable now though.  */
+             tree x = TREE_VALUE (link);
+             while (handled_component_p (x))
+               x = TREE_OPERAND (x, 0);
+             if (TREE_CODE (x) == MEM_REF
+                 && TREE_CODE (TREE_OPERAND (x, 0)) == ADDR_EXPR)
+               x = TREE_OPERAND (TREE_OPERAND (x, 0), 0);
+             if ((TREE_CODE (x) == VAR_DECL
+                  || TREE_CODE (x) == PARM_DECL
+                  || TREE_CODE (x) == RESULT_DECL)
+                 && !TREE_ADDRESSABLE (x)
+                 && is_gimple_reg (x))
+               {
+                 warning_at (EXPR_LOC_OR_LOC (TREE_VALUE (link),
+                                              input_location), 0,
+                             "memory input %d is not directly addressable",
+                             i);
+                 prepare_gimple_addressable (&TREE_VALUE (link), pre_p);
+               }
+           }
          mark_addressable (TREE_VALUE (link));
          if (tret == GS_ERROR)
            {
-             if (EXPR_HAS_LOCATION (TREE_VALUE (link)))
-               input_location = EXPR_LOCATION (TREE_VALUE (link));
-             error ("memory input %d is not directly addressable", i);
+             error_at (EXPR_LOC_OR_LOC (TREE_VALUE (link), input_location),
+                       "memory input %d is not directly addressable", i);
              ret = tret;
            }
        }
index 26d09551faea407b5ceb447d12dbe2e94cd6a359..138f7460c787f95badad118e6b8dc0bcb0fe6227 100644 (file)
@@ -1,6 +1,12 @@
 2016-02-11  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2016-01-21  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/67653
+       * c-c++-common/pr67653.c: New test.
+       * gcc.dg/torture/pr29119.c: Add dg-warning.
+
        2016-01-19  Jakub Jelinek  <jakub@redhat.com>
 
        PR rtl-optimization/68955
diff --git a/gcc/testsuite/c-c++-common/pr67653.c b/gcc/testsuite/c-c++-common/pr67653.c
new file mode 100644 (file)
index 0000000..1b9f63e
--- /dev/null
@@ -0,0 +1,8 @@
+/* PR middle-end/67653 */
+/* { dg-do compile } */
+
+void
+foo (void)
+{
+  __asm__ ("" : : "m" (({ static int a; a; })));       /* { dg-warning "memory input 0 is not directly addressable" } */
+}
index 63e5d8693a97df789f27d6c8e4ad88a42a8c7ab7..d4f02f124563c15d39d0b36a1e9d34ddbf3e48fc 100644 (file)
@@ -2,6 +2,5 @@
 
 void ldt_add_entry(void)
 {
-   __asm__ ("" :: "m"(({unsigned __v; __v;})));
+   __asm__ ("" :: "m"(({unsigned __v; __v;})));        /* { dg-warning "memory input 0 is not directly addressable" } */
 }
-