From patchwork Wed May 21 15:49:06 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Wielaard X-Patchwork-Id: 351234 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 2C132140084 for ; Thu, 22 May 2014 01:49:20 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:from:to:cc:in-reply-to:references:content-type:date :message-id:mime-version; q=dns; s=default; b=xAEvWXX4NpCymfU3Ea dTXfAu6x5ZgL8WOuQgCeDZPdd0ZO5pz3cTEHtPAuz2rlW9r2+FZunlcpP7SpG6cL 5/gF6RcnkKIrfsduMAuFrb6HzLUpjF52k8SgOdEZiF/6xviwQdhSEsEa1kCs+xsJ aGYLblA9GU2D6I6ynPshgNgrA= 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 :subject:from:to:cc:in-reply-to:references:content-type:date :message-id:mime-version; s=default; bh=k0PhRKYenUvlNfehjADnWCbn ZNU=; b=rSgD+0j9Geo7Y9qRD2zUwWJ5os1KKf/7Yx4WJ1CwBLTMinkJvPFBjXb9 k/v1O2IVkHxb09Ef/fJgZY9BII9K1K2Ct2A2hT8A+hLxT8r8ezg4ylWAzL59kqy7 Oz8SgJZ9Xc4v6XYGgEARM0ftS4H5uZLLFWWiPwy9+6mnrfZe6j4= Received: (qmail 8593 invoked by alias); 21 May 2014 15:49:13 -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 8579 invoked by uid 89); 21 May 2014 15:49:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.1 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 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; Wed, 21 May 2014 15:49:11 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s4LFn9qA021701 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 21 May 2014 11:49:10 -0400 Received: from [10.36.116.92] (ovpn-116-92.ams2.redhat.com [10.36.116.92]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s4LFn7Cd001546; Wed, 21 May 2014 11:49:07 -0400 Subject: Re: Ping2: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration. From: Mark Wielaard To: Jason Merrill Cc: Jakub Jelinek , Cary Coutant , Tom Tromey , gcc-patches , Richard Henderson In-Reply-To: <537CB940.5000001@redhat.com> References: <1397510343.5633.44.camel@bordewijk.wildebeest.org> <1398162670.29199.127.camel@bordewijk.wildebeest.org> <1398683852.4016.30.camel@bordewijk.wildebeest.org> <20140428122313.GE1817@tucnak.redhat.com> <1398688641.4016.35.camel@bordewijk.wildebeest.org> <53718FE3.9090108@redhat.com> <20140513072108.GA11487@toonder.wildebeest.org> <537A6E9B.4050304@redhat.com> <20140520065546.GB2916@toonder.wildebeest.org> <537B6A0A.1080409@redhat.com> <20140520175111.GA8845@toonder.wildebeest.org> <537BB12C.4070009@redhat.com> <1400678835.9184.5.camel@bordewijk.wildebeest.org> <537CB940.5000001@redhat.com> Date: Wed, 21 May 2014 17:49:06 +0200 Message-ID: <1400687346.9184.13.camel@bordewijk.wildebeest.org> Mime-Version: 1.0 On Wed, 2014-05-21 at 10:33 -0400, Jason Merrill wrote: > On 05/21/2014 09:27 AM, Mark Wielaard wrote: > > +/* The C++ version of the enum_underlying_base_type langhook. > > + See also cp/semantics.c (finish_underlying_type). */ > > +static tree cxx_enum_underlying_base_type (const_tree type) > > We usually leave a blank line between the comment and the function. > Also, the function name should be at the beginning of the line for etags. Fixed both issues. > > +/* Default implementation of enum_underlying_base_type using type_for_size. */ > > +tree > > +lhd_enum_underlying_base_type (const_tree enum_type) > > Blank line here, too. Added. > > tree (*reconstruct_complex_type) (tree, tree); > > + > > + tree (*enum_underlying_base_type) (const_tree); > > And please add a comment documenting the hook. Documentation added. > OK with those changes. Pushed as attached. Thanks, Mark From 1b006e46754125c47544223aa6ee8a42d102fe4d Mon Sep 17 00:00:00 2001 From: mark Date: Wed, 21 May 2014 15:44:59 +0000 Subject: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration. Add a new lang-hook that provides the underlying base type of an ENUMERAL_TYPE. The default implementation will just use type_for_size. The implementation for C++ will use the ENUM_UNDERLYING_TYPE if it exists. Use this enum_underlying_base_type lang-hook in dwarf2out.c to add a DW_AT_type base type reference to a DW_TAG_enumeration. gcc/ * dwarf2out.c (gen_enumeration_type_die): Add DW_AT_type if DWARF version >= 3 or not strict DWARF. * langhooks.h (struct lang_hooks_for_types): Add enum_underlying_base_type. * langhooks.c (lhd_enum_underlying_base_type): New function. * gcc/langhooks.h (struct lang_hooks_for_types): Add enum_underlying_base_type. * langhooks-def.h (lhd_enum_underlying_base_type): New declaration. (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): New define. (LANG_HOOKS_FOR_TYPES_INITIALIZER): Add new lang hook. gcc/cp/ * cp-lang.c (cxx_enum_underlying_base_type): New function. (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@210717 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 14 ++++++++++++++ gcc/cp/ChangeLog | 6 ++++++ gcc/cp/cp-lang.c | 20 ++++++++++++++++++++ gcc/dwarf2out.c | 5 +++++ gcc/langhooks-def.h | 5 ++++- gcc/langhooks.c | 9 +++++++++ gcc/langhooks.h | 6 ++++++ 7 files changed, 64 insertions(+), 1 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d506727..452b4b0 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,17 @@ +2014-05-21 Mark Wielaard + + PR debug/16063 + * dwarf2out.c (gen_enumeration_type_die): Add DW_AT_type if DWARF + version >= 3 or not strict DWARF. + * langhooks.h (struct lang_hooks_for_types): Add + enum_underlying_base_type. + * langhooks.c (lhd_enum_underlying_base_type): New function. + * gcc/langhooks.h (struct lang_hooks_for_types): Add + enum_underlying_base_type. + * langhooks-def.h (lhd_enum_underlying_base_type): New declaration. + (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): New define. + (LANG_HOOKS_FOR_TYPES_INITIALIZER): Add new lang hook. + 2014-05-21 Richard Biener * doc/invoke.texi (-flto-partition=): Document one and diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index adde47f..b0a06b1 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2014-05-21 Mark Wielaard + + PR debug/16063 + * cp-lang.c (cxx_enum_underlying_base_type): New function. + (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define. + 2014-05-21 Richard Sandiford * cvt.c (convert_to_void): Use void_node instead of void_zero_node. diff --git a/gcc/cp/cp-lang.c b/gcc/cp/cp-lang.c index c28c07a..014f393 100644 --- a/gcc/cp/cp-lang.c +++ b/gcc/cp/cp-lang.c @@ -23,6 +23,7 @@ along with GCC; see the file COPYING3. If not see #include "coretypes.h" #include "tm.h" #include "tree.h" +#include "stor-layout.h" #include "cp-tree.h" #include "c-family/c-common.h" #include "langhooks.h" @@ -40,6 +41,7 @@ static enum classify_record cp_classify_record (tree type); static tree cp_eh_personality (void); static tree get_template_innermost_arguments_folded (const_tree); static tree get_template_argument_pack_elems_folded (const_tree); +static tree cxx_enum_underlying_base_type (const_tree); /* Lang hooks common to C++ and ObjC++ are declared in cp/cp-objcp-common.h; consequently, there should be very few hooks below. */ @@ -81,6 +83,8 @@ static tree get_template_argument_pack_elems_folded (const_tree); #define LANG_HOOKS_EH_PERSONALITY cp_eh_personality #undef LANG_HOOKS_EH_RUNTIME_TYPE #define LANG_HOOKS_EH_RUNTIME_TYPE build_eh_type_type +#undef LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE +#define LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE cxx_enum_underlying_base_type /* Each front end provides its own lang hook initializer. */ struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER; @@ -219,5 +223,21 @@ get_template_argument_pack_elems_folded (const_tree t) return fold_cplus_constants (get_template_argument_pack_elems (t)); } +/* The C++ version of the enum_underlying_base_type langhook. + See also cp/semantics.c (finish_underlying_type). */ + +static +tree cxx_enum_underlying_base_type (const_tree type) +{ + tree underlying_type = ENUM_UNDERLYING_TYPE (type); + + if (! ENUM_FIXED_UNDERLYING_TYPE_P (type)) + underlying_type + = c_common_type_for_mode (TYPE_MODE (underlying_type), + TYPE_UNSIGNED (underlying_type)); + + return underlying_type; +} + #include "gt-cp-cp-lang.h" #include "gtype-cp.h" diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 4ea05a5..7c93074 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -17537,6 +17537,11 @@ gen_enumeration_type_die (tree type, dw_die_ref context_die) TREE_ASM_WRITTEN (type) = 1; add_byte_size_attribute (type_die, type); + if (dwarf_version >= 3 || !dwarf_strict) + { + tree underlying = lang_hooks.types.enum_underlying_base_type (type); + add_type_attribute (type_die, underlying, 0, 0, context_die); + } if (TYPE_STUB_DECL (type) != NULL_TREE) { add_src_coords_attributes (type_die, TYPE_STUB_DECL (type)); diff --git a/gcc/langhooks-def.h b/gcc/langhooks-def.h index 95bd379..d9a1dfd 100644 --- a/gcc/langhooks-def.h +++ b/gcc/langhooks-def.h @@ -60,6 +60,7 @@ extern size_t lhd_tree_size (enum tree_code); extern HOST_WIDE_INT lhd_to_target_charset (HOST_WIDE_INT); extern tree lhd_expr_to_decl (tree, bool *, bool *); extern tree lhd_builtin_function (tree); +extern tree lhd_enum_underlying_base_type (const_tree); /* Declarations of default tree inlining hooks. */ extern void lhd_initialize_diagnostics (diagnostic_context *); @@ -173,6 +174,7 @@ extern tree lhd_make_node (enum tree_code); #define LANG_HOOKS_GET_SUBRANGE_BOUNDS NULL #define LANG_HOOKS_DESCRIPTIVE_TYPE NULL #define LANG_HOOKS_RECONSTRUCT_COMPLEX_TYPE reconstruct_complex_type +#define LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE lhd_enum_underlying_base_type #define LANG_HOOKS_FOR_TYPES_INITIALIZER { \ LANG_HOOKS_MAKE_TYPE, \ @@ -191,7 +193,8 @@ extern tree lhd_make_node (enum tree_code); LANG_HOOKS_GET_ARRAY_DESCR_INFO, \ LANG_HOOKS_GET_SUBRANGE_BOUNDS, \ LANG_HOOKS_DESCRIPTIVE_TYPE, \ - LANG_HOOKS_RECONSTRUCT_COMPLEX_TYPE \ + LANG_HOOKS_RECONSTRUCT_COMPLEX_TYPE, \ + LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE \ } /* Declaration hooks. */ diff --git a/gcc/langhooks.c b/gcc/langhooks.c index d00ebd8..8f65c68 100644 --- a/gcc/langhooks.c +++ b/gcc/langhooks.c @@ -678,3 +678,12 @@ lhd_end_section (void) saved_section = NULL; } } + +/* Default implementation of enum_underlying_base_type using type_for_size. */ + +tree +lhd_enum_underlying_base_type (const_tree enum_type) +{ + return lang_hooks.types.type_for_size (TYPE_PRECISION (enum_type), + TYPE_UNSIGNED (enum_type)); +} diff --git a/gcc/langhooks.h b/gcc/langhooks.h index c848b0c..35b47bc 100644 --- a/gcc/langhooks.h +++ b/gcc/langhooks.h @@ -137,6 +137,12 @@ struct lang_hooks_for_types return values from functions. The argument TYPE is the top of the chain, and BOTTOM is the new type which we will point to. */ tree (*reconstruct_complex_type) (tree, tree); + + /* Returns the tree that represents the underlying data type used to + implement the enumeration. The default implementation will just use + type_for_size. Used in dwarf2out.c to add a DW_AT_type base type + reference to a DW_TAG_enumeration. */ + tree (*enum_underlying_base_type) (const_tree); }; /* Language hooks related to decls and the symbol table. */ -- 1.7.1