From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27955 invoked by alias); 9 Mar 2017 15:49:39 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 27898 invoked by uid 89); 9 Mar 2017 15:49:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= 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, 09 Mar 2017 15:49:36 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 545CE72987; Thu, 9 Mar 2017 15:49:36 +0000 (UTC) Received: from redhat.com (ovpn-204-150.brq.redhat.com [10.40.204.150]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v29FnXb7032396 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 9 Mar 2017 10:49:35 -0500 Date: Thu, 09 Mar 2017 15:49:00 -0000 From: Marek Polacek To: Jakub Jelinek Cc: "Joseph S. Myers" , gcc-patches@gcc.gnu.org Subject: Re: [C PATCH] Fix debug info locus of enum with previous forward declaration (PR c/79969) Message-ID: <20170309154931.GD3172@redhat.com> References: <20170309092443.GF22703@tucnak> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170309092443.GF22703@tucnak> User-Agent: Mutt/1.7.1 (2016-10-04) X-SW-Source: 2017-03/txt/msg00434.txt.bz2 On Thu, Mar 09, 2017 at 10:24:43AM +0100, Jakub Jelinek wrote: > Hi! > > Similarly to https://gcc.gnu.org/ml/gcc-patches/2009-09/msg01161.html > the C FE gets wrong the location of DW_TAG_enumeral_type if there is a > forward declaration. If we e.g. have a variable that is first declared > extern and then defined, we emit DW_TAG_variable with the location of the > first declaration and then another DW_TAG_variable with DW_AT_specification > pointing to the previous one for the definition, with locus of the > definition. That is not what we do for enums, there is just one DIE, so we > should use the more descriptive from the locations, which is the definition. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > 2017-03-09 Jakub Jelinek > > PR c/79969 > * c-decl.c (start_enum): Adjust DECL_SOURCE_LOCATION of > TYPE_STUB_DECL. How about doing this in finish_enum, similarly to finish_struct? You'd need to pass a location from the parser, but that's easy: diff --git gcc/c/c-decl.c gcc/c/c-decl.c index 645304a..5df41dd 100644 --- gcc/c/c-decl.c +++ gcc/c/c-decl.c @@ -8246,7 +8246,7 @@ start_enum (location_t loc, struct c_enum_contents *the_enum, tree name) Returns ENUMTYPE. */ tree -finish_enum (tree enumtype, tree values, tree attributes) +finish_enum (location_t loc, tree enumtype, tree values, tree attributes) { tree pair, tem; tree minnode = 0, maxnode = 0; @@ -8382,6 +8382,11 @@ finish_enum (tree enumtype, tree values, tree attributes) TYPE_LANG_SPECIFIC (tem) = TYPE_LANG_SPECIFIC (enumtype); } + /* Update type location to the one of the definition, instead of e.g. + a forward declaration. */ + if (TYPE_STUB_DECL (enumtype)) + DECL_SOURCE_LOCATION (TYPE_STUB_DECL (enumtype)) = loc; + /* Finish debugging output for this type. */ rest_of_type_compilation (enumtype, toplevel); diff --git gcc/c/c-parser.c gcc/c/c-parser.c index 8330e65..2d9c0d3 100644 --- gcc/c/c-parser.c +++ gcc/c/c-parser.c @@ -2779,7 +2779,7 @@ c_parser_enum_specifier (c_parser *parser) } } postfix_attrs = c_parser_attributes (parser); - ret.spec = finish_enum (type, nreverse (values), + ret.spec = finish_enum (enum_loc, type, nreverse (values), chainon (attrs, postfix_attrs)); ret.kind = ctsk_tagdef; ret.expr = NULL_TREE; diff --git gcc/c/c-tree.h gcc/c/c-tree.h index 13e40e6..3800256 100644 --- gcc/c/c-tree.h +++ gcc/c/c-tree.h @@ -534,7 +534,7 @@ extern void c_release_switch_bindings (struct c_spot_bindings *); extern bool c_check_switch_jump_warnings (struct c_spot_bindings *, location_t, location_t); extern void finish_decl (tree, location_t, tree, tree, tree); -extern tree finish_enum (tree, tree, tree); +extern tree finish_enum (location_t, tree, tree, tree); extern void finish_function (void); extern tree finish_struct (location_t, tree, tree, tree, struct c_struct_parse_info *); Marek