From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 3E7A139960FD; Thu, 17 Sep 2020 17:03:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3E7A139960FD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1600362226; bh=+owAMIu8MmnWL37xSiYUJIphwgw0VsGuFfvJnt42GZE=; h=From:To:Subject:Date:From; b=LlVjcZgmMWTAUYaRvVzG7pHY4Zio1ZmL9DdW5VpVjTQ+T8dOqmrjDaj7oZbzwJwro D1zJTWU61DgzUORsOD+5ZRpc/iq7q3ZRV36ohMzzCn7X9NtKahQeMuxdvDFEcQicMX TcAyOhyyVKGsHgv1K+IYSn2i8YsPL4pNY+2mifmQ= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/redhat/heads/gcc-8-branch)] c++: generic lambda and -fsanitize=vla-bound [PR93822] X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/vendors/redhat/heads/gcc-8-branch X-Git-Oldrev: 706efa6248736efa93ca628540a0d93e32f451c6 X-Git-Newrev: 2a4634e6d87fc7094104084a86b038c5ab7d0fe2 Message-Id: <20200917170346.3E7A139960FD@sourceware.org> Date: Thu, 17 Sep 2020 17:03:46 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Sep 2020 17:03:46 -0000 https://gcc.gnu.org/g:2a4634e6d87fc7094104084a86b038c5ab7d0fe2 commit 2a4634e6d87fc7094104084a86b038c5ab7d0fe2 Author: Jason Merrill Date: Mon May 25 18:38:09 2020 -0400 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 PR c++/93822 * pt.c (tsubst_decl): Make sure DECL_VALUE_EXPR continues to have the same type as the variable. Diff: --- gcc/cp/pt.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 4673c27468e..2d38310f1fb 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -13817,6 +13817,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)) @@ -13824,6 +13829,10 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain) gcc_assert (TREE_CODE (type) == REFERENCE_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)