From patchwork Sat Apr 20 06:14:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1088286 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-499497-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="IIFDNKhe"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44mMyD5kGHz9s5c for ; Sat, 20 Apr 2019 16:14:53 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version :content-transfer-encoding; q=dns; s=default; b=JeVI/qqd28gK8dml 9BEkB/q8mJUtVI3uWwVRx8l58NzoFQMf13RdftV2rxEekQFYtADrT3Pl72MtHbkm f99wvlji1EpUQa688tLrFYLQeE64Nu4QESKaLLgz225LnzDV45vUwQc9AF5CNb9b XJtKMwZUfRac9yMIugWG09ibF9E= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version :content-transfer-encoding; s=default; bh=ZyPhENYClj5EGbpPue2rh6 VF9K8=; b=IIFDNKhefwKIMdoHySoPDOPMC8dHcD/kC1eH8sd4o42VtuFHfG6u4a N7fZnMXOc6Ul5Hx9dJtIMPcxVFu3Yhzt4MZ1EI92G5Q9/fPOnp2X046EqtBUCeWc JTMhYXpckGgazyFUc9sD7DuTTFSn0YNzS46+DWFXQemEsfq/8cGp8= Received: (qmail 10989 invoked by alias); 20 Apr 2019 06:14:45 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 10981 invoked by uid 89); 20 Apr 2019 06:14:45 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=delete_A, HX-Spam-Relays-External:209.85.222.196, delete_a, same_type_p X-HELO: mail-qk1-f196.google.com Received: from mail-qk1-f196.google.com (HELO mail-qk1-f196.google.com) (209.85.222.196) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 20 Apr 2019 06:14:43 +0000 Received: by mail-qk1-f196.google.com with SMTP id p185so3800110qkb.8 for ; Fri, 19 Apr 2019 23:14:43 -0700 (PDT) Received: from orpheus.redhat.com (75-172-108-189.tukw.qwest.net. [75.172.108.189]) by smtp.gmail.com with ESMTPSA id x5sm3300850qki.26.2019.04.19.23.14.35 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 19 Apr 2019 23:14:40 -0700 (PDT) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] PR c++/90171 - ICE with destroying delete with size_t parm. Date: Fri, 19 Apr 2019 23:14:19 -0700 Message-Id: <20190420061419.19585-1-jason@redhat.com> MIME-Version: 1.0 X-IsSubscribed: yes The problem here was that "second parm is size_t" is false for a destroying sized delete. So let's introduce sized_deallocation_fn_p when that's what we're asking, and reserve second_parm_is_size_t for the specific case of warning about possible confusion with placement delete. Tested x86_64-pc-linux-gnu, applying to trunk. * call.c (sized_deallocation_fn_p): New. Use it instead of second_parm_is_size_t in most cases. (second_parm_is_size_t): Don't check for aligned. --- gcc/cp/call.c | 44 ++++++++++++------- .../g++.dg/cpp2a/destroying-delete4.C | 11 +++++ gcc/cp/ChangeLog | 7 +++ 3 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/destroying-delete4.C base-commit: dbb68bd891ba4d345f3667c3ae7f1bfda04233b2 diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 9582345d7e8..f27a80dfa3b 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -6307,10 +6307,6 @@ second_parm_is_size_t (tree fn) t = TREE_CHAIN (t); if (t == void_list_node) return true; - if (aligned_new_threshold && t - && same_type_p (TREE_VALUE (t), align_type_node) - && TREE_CHAIN (t) == void_list_node) - return true; return false; } @@ -6383,6 +6379,26 @@ aligned_deallocation_fn_p (tree t) return false; } +/* Returns true if FN is a usual deallocation fn with a size_t parameter. */ + +static bool +sized_deallocation_fn_p (tree fn) +{ + tree t = FUNCTION_ARG_CHAIN (fn); + if (destroying_delete_p (fn)) + t = TREE_CHAIN (t); + if (!t || !same_type_p (TREE_VALUE (t), size_type_node)) + return false; + t = TREE_CHAIN (t); + if (t == void_list_node) + return true; + if (aligned_new_threshold && t + && same_type_p (TREE_VALUE (t), align_type_node) + && TREE_CHAIN (t) == void_list_node) + return true; + return false; +} + /* Returns true iff T, an element of an OVERLOAD chain, is a usual deallocation function (3.7.4.2 [basic.stc.dynamic.deallocation]). */ @@ -6395,13 +6411,11 @@ usual_deallocation_fn_p (tree t) || primary_template_specialization_p (t)) return false; - /* If a class T has a member deallocation function named operator delete - with exactly one parameter, then that function is a usual - (non-placement) deallocation function. If class T does not declare - such an operator delete but does declare a member deallocation - function named operator delete with exactly two parameters, the second - of which has type std::size_t (18.2), then this function is a usual - deallocation function. */ + /* A usual deallocation function is a deallocation function whose parameters + after the first are + - optionally, a parameter of type std::destroying_delete_t, then + - optionally, a parameter of type std::size_t, then + - optionally, a parameter of type std::align_val_t. */ bool global = DECL_NAMESPACE_SCOPE_P (t); tree chain = FUNCTION_ARG_CHAIN (t); if (!chain) @@ -6410,7 +6424,7 @@ usual_deallocation_fn_p (tree t) chain = TREE_CHAIN (chain); if (chain == void_list_node || ((!global || flag_sized_deallocation) - && second_parm_is_size_t (t))) + && sized_deallocation_fn_p (t))) return true; if (aligned_deallocation_fn_p (t)) return true; @@ -6625,8 +6639,8 @@ build_op_delete_call (enum tree_code code, tree addr, tree size, /* We need a cookie to determine the array size. */ want_size = false; } - bool fn_size = second_parm_is_size_t (fn); - bool elt_size = second_parm_is_size_t (elt); + bool fn_size = sized_deallocation_fn_p (fn); + bool elt_size = sized_deallocation_fn_p (elt); gcc_assert (fn_size != elt_size); if (want_size == elt_size) fn = elt; @@ -6682,7 +6696,7 @@ build_op_delete_call (enum tree_code code, tree addr, tree size, args->quick_push (addr); if (destroying) args->quick_push (destroying); - if (second_parm_is_size_t (fn)) + if (sized_deallocation_fn_p (fn)) args->quick_push (size); if (aligned_deallocation_fn_p (fn)) { diff --git a/gcc/testsuite/g++.dg/cpp2a/destroying-delete4.C b/gcc/testsuite/g++.dg/cpp2a/destroying-delete4.C new file mode 100644 index 00000000000..c122cee4942 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/destroying-delete4.C @@ -0,0 +1,11 @@ +// PR c++/90171 +// { dg-do compile { target c++2a } } + +#include + +struct A { + void operator delete(A*, std::destroying_delete_t, std::align_val_t); + void operator delete(A*, std::destroying_delete_t, std::size_t, std::align_val_t); +}; + +void delete_A(A *a) { delete a; } diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 9c1c49bda28..e7521446b59 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2019-04-19 Jason Merrill + + PR c++/90171 - ICE with destroying delete with size_t parm. + * call.c (sized_deallocation_fn_p): New. Use it instead of + second_parm_is_size_t in most cases. + (second_parm_is_size_t): Don't check for aligned. + 2019-04-19 Jakub Jelinek PR c++/90108