From patchwork Thu Mar 14 20:14:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 1056690 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-497925-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="QxnQQ+VH"; 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 44L0Ll1Lgkz9s00 for ; Fri, 15 Mar 2019 07:15:07 +1100 (AEDT) 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:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=rEh8GnWa1OV2GKD7 xspvr0T9Kjwv8HHn62gAH2edV319CTPbFCb4XogD7La84wJd47K6tklHWdDHmzB4 3VAq+zsOunYZcI+QbCeiZqYd1joLQWa0b/3cW5J586KQ/GOvB/vwqZsX3mTeeusn cEiA2rM3uzKENQNJG8DEuQYez/A= 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:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=VpWhvwbneTpED6iLOaSAfH v2nEE=; b=QxnQQ+VHzoO7/UsL74rJ/lr0kqAlc7n7eNq9+cdBwRBMUadqFy6TaL N6ySSQYApOaWwxcsKW4ea+7n09ryFMIjF+WaNnVCfkYs4bBAHVxEBQiJfT5zlP+O vU7iedWVsB/LXCscf2HvpgcVjZZhN5CqpeChRBUbk573AMEcljOsQ= Received: (qmail 29192 invoked by alias); 14 Mar 2019 20:14:59 -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 29163 invoked by uid 89); 14 Mar 2019 20:14:59 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-15.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=hay, pero, sk:DW_AT_c, sk:dw_at_c X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 14 Mar 2019 20:14:58 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E84453084049; Thu, 14 Mar 2019 20:14:56 +0000 (UTC) Received: from free.home (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A880C5D9C8; Thu, 14 Mar 2019 20:14:56 +0000 (UTC) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTP id x2EKEnn5944381; Thu, 14 Mar 2019 17:14:49 -0300 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, nathan@acm.org, ccoutant@gmail.com Subject: [C++ debug PATCH] [PR88534] accept VAR_DECL in class literal template parms Date: Thu, 14 Mar 2019 17:14:49 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 P0732R2 / C++ 2a introduce class literals as template parameters. The front-end uses VAR_DECLs constructed from such literals to bind the template PARM_DECLs, but dwarf2out.c used to reject such VAR_DECLs. Taking DECL_INITIAL from such VAR_DECLs enables the generation of DW_AT_const_value for them, at least when the class literal can actually be represented as such. Regstrapped on x86_64- and i686-linux-gnu. Ok to install? for gcc/ChangeLog PR c++/88534 PR c++/88537 * dwarf2out.c (generic_parameter_die): Follow DECL_INITIAL of VAR_DECL args. for gcc/ChangeLog PR c++/88534 PR c++/88537 * g++.dg/cpp2a/pr88534.C: New. * g++.dg/cpp2a/pr88537.C: New. --- gcc/dwarf2out.c | 7 ++++ gcc/testsuite/g++.dg/cpp2a/pr88534.C | 65 ++++++++++++++++++++++++++++++++++ gcc/testsuite/g++.dg/cpp2a/pr88537.C | 16 ++++++++ 3 files changed, 88 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp2a/pr88534.C create mode 100644 gcc/testsuite/g++.dg/cpp2a/pr88537.C diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 8305555681447..478d9b9b289b1 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -13601,6 +13601,13 @@ generic_parameter_die (tree parm, tree arg, dw_die_ref tmpl_die = NULL; const char *name = NULL; + /* C++2a accepts class literals as template parameters, and var + decls with initializers represent them. The VAR_DECLs would be + rejected, but we can take the DECL_INITIAL constructor and + attempt to expand it. */ + if (TREE_CODE (arg) == VAR_DECL) + arg = DECL_INITIAL (arg); + if (!parm || !DECL_NAME (parm) || !arg) return NULL; diff --git a/gcc/testsuite/g++.dg/cpp2a/pr88534.C b/gcc/testsuite/g++.dg/cpp2a/pr88534.C new file mode 100644 index 0000000000000..54faf385f11aa --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/pr88534.C @@ -0,0 +1,65 @@ +// { dg-do compile { target c++2a } } +// { dg-options "-g" } + +typedef __SIZE_TYPE__ size_t; + +namespace std +{ + +template +struct integer_sequence +{ + typedef T value_type; + static constexpr size_t size () noexcept { return sizeof...(I); } +}; + +template +using make_integer_sequence = integer_sequence; + +template +using index_sequence = integer_sequence; + +template +using make_index_sequence = make_integer_sequence; +} + +template struct S +{ + T content[N]; + using char_type = T; + template + constexpr S (const T (&input)[N], std::index_sequence) noexcept : content{input[I]...} { } + constexpr S (const T (&input)[N]) noexcept : S (input, std::make_index_sequence ()) { } + constexpr size_t size () const noexcept + { + if (content[N - 1] == '\0') + return N - 1; + else + return N; + } + constexpr T operator[] (size_t i) const noexcept + { + return content[i]; + } + constexpr const T *begin () const noexcept + { + return content; + } + constexpr const T *end () const noexcept + { + return content + size (); + } +}; + +template S (const T (&)[N]) -> S; + +template +struct F +{ +}; + +auto +foo () +{ + F<"test"> f; +} diff --git a/gcc/testsuite/g++.dg/cpp2a/pr88537.C b/gcc/testsuite/g++.dg/cpp2a/pr88537.C new file mode 100644 index 0000000000000..d558d45f57830 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/pr88537.C @@ -0,0 +1,16 @@ +// { dg-do compile { target c++2a } } +// { dg-options "-g" } + +struct pair { + unsigned a; + unsigned b; + constexpr pair(unsigned _a, unsigned _b) noexcept: a{_a}, b{_b} { } +}; + +template void fnc() { + +} + +void f() { + fnc(); +}