From patchwork Tue Sep 7 18:41:07 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 64050 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]) by ozlabs.org (Postfix) with SMTP id B54FEB6F01 for ; Wed, 8 Sep 2010 04:41:20 +1000 (EST) Received: (qmail 28465 invoked by alias); 7 Sep 2010 18:41:17 -0000 Received: (qmail 28454 invoked by uid 22791); 7 Sep 2010 18:41:15 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (212.99.106.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 07 Sep 2010 18:41:10 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 60EF7CB0250; Tue, 7 Sep 2010 20:41:08 +0200 (CEST) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id MfsdwHR1Yet0; Tue, 7 Sep 2010 20:41:08 +0200 (CEST) Received: from saumur.act-europe.fr (saumur.act-europe.fr [10.10.0.183]) by mel.act-europe.fr (Postfix) with ESMTP id 32DC5CB0223; Tue, 7 Sep 2010 20:41:08 +0200 (CEST) Received: by saumur.act-europe.fr (Postfix, from userid 525) id E645BD9BA8; Tue, 7 Sep 2010 20:41:07 +0200 (CEST) Date: Tue, 7 Sep 2010 20:41:07 +0200 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org, joseph@codesourcery.com, rth@redhat.com Subject: [C patch] use better sloc for enum literals Message-ID: <20100907184107.GA3907@adacore.com> Mime-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.9i X-IsSubscribed: yes 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 This is the C front-end patch corresponding to the following C++ change: http://gcc.gnu.org/ml/gcc-patches/2010-09/msg00520.html This is for setting the sloc of an enum literal decl to its declaration rather than to the location of the '=' operator (when present) as in: enum enum1 { FOO = 1, BAR = 2 }; This patch keeps the current behavior when generating error messages related to the enum values which point to the '=' operator sloc, so no tests are impacted. Tested on x86_64-pc-linux-gnu, OK for trunk? 2010-09-07 Arnaud Charlet * c-tree.h, c-decl.c (build_enumerator): Add location parameter. * c-parser.c (c_parser_enum_specifier): Adjust call to build_enumerator. Index: c-tree.h =================================================================== --- c-tree.h (revision 163920) +++ c-tree.h (working copy) @@ -427,7 +427,8 @@ extern int quals_from_declspecs (const s extern struct c_declarator *build_array_declarator (location_t, tree, struct c_declspecs *, bool, bool); -extern tree build_enumerator (location_t, struct c_enum_contents *, tree, tree); +extern tree build_enumerator (location_t, location_t, struct c_enum_contents *, + tree, tree); extern tree check_for_loop_decls (location_t); extern void mark_forward_parm_decls (void); extern void declare_parm_level (void); Index: c-decl.c =================================================================== --- c-decl.c (revision 163920) +++ c-decl.c (working copy) @@ -7343,12 +7343,13 @@ finish_enum (tree enumtype, tree values, /* Build and install a CONST_DECL for one value of the current enumeration type (one that was begun with start_enum). - LOC is the location of the enumerator. + DECL_LOC is the location of the enumerator. + LOC is the location of the '=' operator if any, DECL_LOC otherwise. Return a tree-list containing the CONST_DECL and its value. Assignment of sequential values by default is handled here. */ tree -build_enumerator (location_t loc, +build_enumerator (location_t decl_loc, location_t loc, struct c_enum_contents *the_enum, tree name, tree value) { tree decl, type; @@ -7436,7 +7437,7 @@ build_enumerator (location_t loc, >= TYPE_PRECISION (integer_type_node) && TYPE_UNSIGNED (type))); - decl = build_decl (loc, CONST_DECL, name, type); + decl = build_decl (decl_loc, CONST_DECL, name, type); DECL_INITIAL (decl) = convert (type, value); pushdecl (decl); Index: c-parser.c =================================================================== --- c-parser.c (revision 163920) +++ c-parser.c (working copy) @@ -1833,7 +1833,7 @@ c_parser_enum_specifier (c_parser *parse bool seen_comma; c_token *token; location_t comma_loc = UNKNOWN_LOCATION; /* Quiet warning. */ - location_t value_loc; + location_t decl_loc, value_loc; if (c_parser_next_token_is_not (parser, CPP_NAME)) { c_parser_error (parser, "expected identifier"); @@ -1845,7 +1845,7 @@ c_parser_enum_specifier (c_parser *parse enum_id = token->value; /* Set the location in case we create a decl now. */ c_parser_set_source_position_from_token (token); - value_loc = token->location; + decl_loc = value_loc = token->location; c_parser_consume_token (parser); if (c_parser_next_token_is (parser, CPP_EQ)) { @@ -1855,7 +1855,7 @@ c_parser_enum_specifier (c_parser *parse } else enum_value = NULL_TREE; - enum_decl = build_enumerator (value_loc, + enum_decl = build_enumerator (decl_loc, value_loc, &the_enum, enum_id, enum_value); TREE_CHAIN (enum_decl) = values; values = enum_decl;