PR c++/88394 - ICE with VLA init-capture.
authorJason Merrill <jason@redhat.com>
Fri, 22 Feb 2019 02:47:33 +0000 (21:47 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 22 Feb 2019 02:47:33 +0000 (21:47 -0500)
We mostly use is_normal_capture_proxy to decide whether or not to use
DECL_CAPTURED_VARIABLE; we could just check whether it's set.  VLA capture
is still mostly broken, but this fixes this ICE.

* lambda.c (is_normal_capture_proxy): Check DECL_CAPTURED_VARIABLE.

From-SVN: r269094

gcc/cp/ChangeLog
gcc/cp/lambda.c
gcc/testsuite/g++.dg/cpp1y/lambda-init-vla1.C [new file with mode: 0644]

index 013bca5938027c6d06f05ca1b4d710072fb200b0..a41044683fe17fa9a086595b96063af518af231b 100644 (file)
@@ -1,5 +1,8 @@
 2019-02-21  Jason Merrill  <jason@redhat.com>
 
+       PR c++/88394 - ICE with VLA init-capture.
+       * lambda.c (is_normal_capture_proxy): Check DECL_CAPTURED_VARIABLE.
+
        PR c++/88869 - C++17 ICE with CTAD and explicit specialization.
        * pt.c (do_class_deduction): Don't include explicit specialization
        args in outer_args.
index 3b803ad86a6abcbbcf32639effb04eb6859c3f67..7032168fb7b0ddf57f6a39e09344a4a28bd39c16 100644 (file)
@@ -279,20 +279,8 @@ is_normal_capture_proxy (tree decl)
     /* It's not a capture proxy.  */
     return false;
 
-  if (variably_modified_type_p (TREE_TYPE (decl), NULL_TREE))
-    /* VLA capture.  */
-    return true;
-
-  /* It is a capture proxy, is it a normal capture?  */
-  tree val = DECL_VALUE_EXPR (decl);
-  if (val == error_mark_node)
-    return true;
-
-  if (TREE_CODE (val) == ADDR_EXPR)
-    val = TREE_OPERAND (val, 0);
-  gcc_assert (TREE_CODE (val) == COMPONENT_REF);
-  val = TREE_OPERAND (val, 1);
-  return DECL_NORMAL_CAPTURE_P (val);
+  return (DECL_LANG_SPECIFIC (decl)
+         && DECL_CAPTURED_VARIABLE (decl));
 }
 
 /* Returns true iff DECL is a capture proxy for a normal capture
diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-init-vla1.C b/gcc/testsuite/g++.dg/cpp1y/lambda-init-vla1.C
new file mode 100644 (file)
index 0000000..1fef7b4
--- /dev/null
@@ -0,0 +1,12 @@
+// PR c++/88394
+// { dg-do compile { target c++14 } }
+// { dg-options "" }
+
+void crash_me(unsigned short sz)
+{
+  if (sz == 0) return;
+
+  short iov[sz];
+  auto fce = [&iv = iov](short value) { iv[0] = 0; };
+  fce(1);
+}