aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2020-05-01 13:53:32 -0400
committerJason Merrill <jason@redhat.com>2020-05-01 13:53:32 -0400
commitbcbf334afe091ad7d0f5ffe164299f8730cf41d1 (patch)
tree5d5c1f2cf82369bb41a4ed14a2ba97fdfba27181 /gcc
parentafb9b7108104a73e8ac7a9b8e6875870e5ca4bbb (diff)
downloadgcc-bcbf334afe091ad7d0f5ffe164299f8730cf41d1.zip
gcc-bcbf334afe091ad7d0f5ffe164299f8730cf41d1.tar.gz
gcc-bcbf334afe091ad7d0f5ffe164299f8730cf41d1.tar.bz2
c++: generic lambda and -fsanitize=vla-bound [PR93822]
Within the generic lambda the VLA capture proxy VAR_DECL has DECL_VALUE_EXPR which is a NOP_EXPR to the VLA type of the proxy. The problem here was that when instantiating we were tsubsting that type twice, once for the type of the DECL and once for the type of the NOP_EXPR, and getting two different (though equivalent) types. Then gimplify_type_sizes fixed up the type of the DECL, but that didn't affect the type of the NOP_EXPR, leading to sadness. Fixed by directly reusing the type from the DECL. gcc/cp/ChangeLog 2020-05-01 Jason Merrill <jason@redhat.com> PR c++/93822 * pt.c (tsubst_decl): Make sure DECL_VALUE_EXPR continues to have the same type as the variable.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/pt.c9
2 files changed, 15 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 3c57945..039e946 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2020-05-01 Jason Merrill <jason@redhat.com>
+
+ PR c++/93822
+ * pt.c (tsubst_decl): Make sure DECL_VALUE_EXPR continues to have
+ the same type as the variable.
+
2020-04-30 Jason Merrill <jason@redhat.com>
Nathan Sidwell <nathan@acm.org>
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index d28585e..9332865 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -14609,6 +14609,11 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain)
if (DECL_HAS_VALUE_EXPR_P (t))
{
tree ve = DECL_VALUE_EXPR (t);
+ /* If the DECL_VALUE_EXPR is converted to the declared type,
+ preserve the identity so that gimplify_type_sizes works. */
+ bool nop = (TREE_CODE (ve) == NOP_EXPR);
+ if (nop)
+ ve = TREE_OPERAND (ve, 0);
ve = tsubst_expr (ve, args, complain, in_decl,
/*constant_expression_p=*/false);
if (REFERENCE_REF_P (ve))
@@ -14616,6 +14621,10 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain)
gcc_assert (TYPE_REF_P (type));
ve = TREE_OPERAND (ve, 0);
}
+ if (nop)
+ ve = build_nop (type, ve);
+ else
+ gcc_checking_assert (TREE_TYPE (ve) == type);
SET_DECL_VALUE_EXPR (r, ve);
}
if (CP_DECL_THREAD_LOCAL_P (r)