]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: generic lambda and -fsanitize=vla-bound [PR93822]
authorJason Merrill <jason@redhat.com>
Mon, 25 May 2020 22:38:09 +0000 (18:38 -0400)
committerJason Merrill <jason@redhat.com>
Mon, 25 May 2020 22:38:09 +0000 (18:38 -0400)
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.

gcc/cp/ChangeLog
gcc/cp/pt.c

index 1b0b35c0ff240c5e1910105c4fb9c763658fc996..9ac4220130e6b38d16831b355d8f9b93d4ee87d5 100644 (file)
@@ -1,3 +1,9 @@
+2020-05-25  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-05-06  Nathan Sidwell  <nathan@acm.org>
 
        PR c++/94946
index a4bbcb4e5d5e029d62c8949e22b8287e2a73979c..7f8138aa479e47a731e77fff65da2290aa2a635c 100644 (file)
@@ -13956,6 +13956,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))
@@ -13963,6 +13968,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)