]> gcc.gnu.org Git - gcc.git/commitdiff
PR c++/88613 - ICE with use of const var in lambda.
authorJason Merrill <jason@redhat.com>
Fri, 11 Jan 2019 22:36:20 +0000 (17:36 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 11 Jan 2019 22:36:20 +0000 (17:36 -0500)
The issue here was that we were cp_folding a location wrapper around a
lambda capture proxy before it had been mark_rvalue_used.  I considered
adding mark_rvalue_use calls to build_new_op_1, but it seems appropriate to
have them in cp_fold_maybe_rvalue when we know we're trying to produce an
rvalue.

The change to mark_use is for a related issue: when we change the operand of
the location wrapper from VAR_DECL to INTEGER_CST, we need the TREE_CODE of
the location wrapper to change as well, from VIEW_CONVERT_EXPR to
NON_LVALUE_EXPR.

* expr.c (mark_use): Fix location wrapper handling.
* cp-gimplify.c (cp_fold_maybe_rvalue): Call mark_rvalue_use.

From-SVN: r267859

gcc/cp/ChangeLog
gcc/cp/cp-gimplify.c
gcc/cp/expr.c
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-const10.C [new file with mode: 0644]

index 5a5256f13fc5b5d57cbe4eb7ce8dfe1a96e274c3..9208f1e4937a39cef7b96e7679fe5eb868633afb 100644 (file)
@@ -1,3 +1,9 @@
+2019-01-11  Jason Merrill  <jason@redhat.com>
+
+       PR c++/88613 - ICE with use of const var in lambda.
+       * expr.c (mark_use): Fix location wrapper handling.
+       * cp-gimplify.c (cp_fold_maybe_rvalue): Call mark_rvalue_use.
+
 2019-01-11  Tobias Burnus  <burnus@net-b.de>
 
        PR C++/88114
index 726adac4f4eef9695d4e8bc7ea6c96c6c98346fd..121dfa41d8d2a7f405b3751e5d48d8185e7d5138 100644 (file)
@@ -2124,6 +2124,8 @@ cp_fold_maybe_rvalue (tree x, bool rval)
   while (true)
     {
       x = cp_fold (x);
+      if (rval)
+       x = mark_rvalue_use (x);
       if (rval && DECL_P (x)
          && !TYPE_REF_P (TREE_TYPE (x)))
        {
index 071c6fb920564a3805c40cf0e5c0070f7dadb7eb..9160043ed114ce11b0d8f47767a8661e50e0217c 100644 (file)
@@ -187,10 +187,23 @@ mark_use (tree expr, bool rvalue_p, bool read_p,
        }
       break;
 
-    CASE_CONVERT:
     case VIEW_CONVERT_EXPR:
       if (location_wrapper_p (expr))
-       loc = EXPR_LOCATION (expr);
+       {
+         loc = EXPR_LOCATION (expr);
+         tree op = TREE_OPERAND (expr, 0);
+         tree nop = RECUR (op);
+         if (nop == error_mark_node)
+           return error_mark_node;
+         TREE_OPERAND (expr, 0) = nop;
+         /* If we're replacing a DECL with a constant, we also need to change
+            the TREE_CODE of the location wrapper.  */
+         if (op != nop && rvalue_p)
+           TREE_SET_CODE (expr, NON_LVALUE_EXPR);
+         return expr;
+       }
+      gcc_fallthrough();
+    CASE_CONVERT:
       recurse_op[0] = true;
       break;
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-const10.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-const10.C
new file mode 100644 (file)
index 0000000..3112f08
--- /dev/null
@@ -0,0 +1,11 @@
+// PR c++/88613
+// { dg-do compile { target c++11 } }
+// { dg-additional-options -Wtautological-compare }
+
+void a() {
+  const int b = 5;
+  [=] {
+    if (b != 5)
+      ;
+  }();
+}
This page took 0.071016 seconds and 5 git commands to generate.