From patchwork Tue Apr 10 19:49:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 151687 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 92837B6FF7 for ; Wed, 11 Apr 2012 05:50:05 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1334692205; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:From:To:Cc:Subject:References:Date:In-Reply-To: Message-ID:User-Agent:MIME-Version:Content-Type:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=f0c1xrJzxfSWkL44ly7OeqiPJak=; b=x0/ErfZ/80jYTqrwrxnxXxUjz44XqVbFHT+zGu/EPTWoldYE87B2RJcjyn7hkt R5o1DYQAzkqBTURYZipKnlclTCFkyewP4LYs9AO1lqWiYxYshrtm7lQLUeXmel// NkGwcj1oQBfxdlahbDPaMsmNAgPV/Yv5OCmfZYbLblThU= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:From:To:Cc:Subject:References:X-URL:Date:In-Reply-To:Message-ID:User-Agent:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=GTUhx1R0062ODYwV6zmBxONxz6tt2qr44UJGKMFJlYq59LJ2N/KkrFMr7JWr0V DeXA7qX/veaASNoVlO8jskp2a583eTdO2m4Qsakig/fcdFb5tTuYo6e+Sh+LA1bX +CxMfL35T7Cd868lCuk3TeQSGufxeeocT+NTwVWnWmnMg=; Received: (qmail 13391 invoked by alias); 10 Apr 2012 19:50:01 -0000 Received: (qmail 13383 invoked by uid 22791); 10 Apr 2012 19:49:59 -0000 X-SWARE-Spam-Status: No, hits=-5.8 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 10 Apr 2012 19:49:44 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q3AJnhtX007268 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 10 Apr 2012 15:49:43 -0400 Received: from localhost (ovpn-116-19.ams2.redhat.com [10.36.116.19]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q3AJngcG009829 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 10 Apr 2012 15:49:43 -0400 Received: by localhost (Postfix, from userid 500) id 841EF29C046; Tue, 10 Apr 2012 21:49:41 +0200 (CEST) From: Dodji Seketeli To: GCC Patches Cc: Tom Tromey , Jason Merrill , Gabriel Dos Reis Subject: [PATCH 05/11] Make expand_location resolve to locus in main source file References: X-URL: http://www.redhat.com Date: Tue, 10 Apr 2012 21:49:41 +0200 In-Reply-To: (Dodji Seketeli's message of "Tue, 10 Apr 2012 16:53:12 +0200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) MIME-Version: 1.0 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 Apparently, quite some places in the compiler (like the C/C++ preprocessor, the debug info machinery) expect expand_location to resolve to locations that are in the main source file, even if the token at stake comes from a macro that was defined in a header somewhere. Turning on -ftrack-macro-expansion by default was triggering a lot of failures (not necessarily related to diagnostics) because expand_location resolves to spelling locations instead. So I have changed expand_location to honour the initial expectation. In addition, I came up with the new expand_location_to_spelling_point used in diagnostic_build_prefix because the diagnostic system, on the other hand, wants to point to the location of the token where it was spelled, and then display the error context involving all the macro whose expansion led to that spelling point - if we are in the context of a macro expansion there. This seems to me like a reasonable balance. Tested and bootstrapped on x86_64-unknown-linux-gnu against trunk and whitnessed that a lot more tests were PASSing. Note that the bootstrap with -ftrack-macro-expansion exhibits other separate issues that are addressed in subsequent patches. This patch just fixes one class of problems. The patch does pass bootstrap with -ftrack-macro-expansion turned off, though. gcc/ * input.c (expand_location_1): New. Takes a parameter to choose whether to resolve the location to spelling or expansion point. Was factorized from ... (expand_location): ... here. (expand_location_to_spelling_point): New. Implemented in terms of expand_location_1. * diagnostic.c (diagnostic_build_prefix): Use the new expand_location_to_spelling_point instead of expand_location. --- gcc/diagnostic.c | 2 +- gcc/input.c | 39 ++++++++++++++++++++++++++++++++++----- gcc/input.h | 9 +++++++++ 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c index a68d6ce..337328c 100644 --- a/gcc/diagnostic.c +++ b/gcc/diagnostic.c @@ -183,7 +183,7 @@ diagnostic_build_prefix (diagnostic_context *context, "must-not-happen" }; const char *text = _(diagnostic_kind_text[diagnostic->kind]); - expanded_location s = expand_location (diagnostic->location); + expanded_location s = expand_location_to_spelling_point (diagnostic->location); if (diagnostic->override_column) s.column = diagnostic->override_column; gcc_assert (diagnostic->kind < DK_LAST_DIAGNOSTIC_KIND); diff --git a/gcc/input.c b/gcc/input.c index 4077f9e..dcd348b 100644 --- a/gcc/input.c +++ b/gcc/input.c @@ -32,16 +32,22 @@ struct line_maps *line_table; /* Expand the source location LOC into a human readable location. If LOC resolves to a builtin location, the file name of the readable - location is set to the string "". */ - -expanded_location -expand_location (source_location loc) + location is set to the string "". If EXPANSION_POINT_P is + TRUE and LOC is virtual, then it is resolved to the expansion + point of the involved macro. Otherwise, it is resolved to the + spelling location of the token. */ + +static expanded_location +expand_location_1 (source_location loc, + bool expansion_point_p) { expanded_location xloc; const struct line_map *map; loc = linemap_resolve_location (line_table, loc, - LRK_SPELLING_LOCATION, &map); + expansion_point_p + ? LRK_MACRO_EXPANSION_POINT + : LRK_SPELLING_LOCATION, &map); xloc = linemap_expand_location (line_table, map, loc); if (loc <= BUILTINS_LOCATION) @@ -50,6 +56,29 @@ expand_location (source_location loc) return xloc; } +/* Expand the source location LOC into a human readable location. If + LOC is virtual, it resolves to the expansion point of the involved + macro. If LOC resolves to a builtin location, the file name of the + readable location is set to the string "". */ + +expanded_location +expand_location (source_location loc) +{ + return expand_location_1 (loc, /*expansion_point_p=*/true); +} + +/* Expand the source location LOC into a human readable location. If + LOC is virtual, it resolves to the expansion location of the + relevant macro. If LOC resolves to a builtin location, the file + name of the readable location is set to the string + "". */ + +expanded_location +expand_location_to_spelling_point (source_location loc) +{ + return expand_location_1 (loc, /*expansion_piont_p=*/false); +} + #define ONE_K 1024 #define ONE_M (ONE_K * ONE_K) diff --git a/gcc/input.h b/gcc/input.h index f2f3513..5838153 100644 --- a/gcc/input.h +++ b/gcc/input.h @@ -38,6 +38,7 @@ extern char builtins_location_check[(BUILTINS_LOCATION < RESERVED_LOCATION_COUNT) ? 1 : -1]; extern expanded_location expand_location (source_location); +extern expanded_location expand_location_to_spelling_point (source_location); /* Historically GCC used location_t, while cpp used source_location. This could be removed but it hardly seems worth the effort. */ @@ -49,6 +50,14 @@ extern location_t input_location; #define LOCATION_LINE(LOC) ((expand_location (LOC)).line) #define LOCATION_COLUMN(LOC)((expand_location (LOC)).column) +#define EXPANSION_POINT_LOCATION_FILE(LOC) \ + ((expand_location_to_expansion_point (LOC)).file) +#define EXPANSION_POINT_LOCATION_LINE(LOC) \ + ((expand_location_to_expansion_point (LOC)).line) +#define EXPANSION_POINT_LOCATION_COLUMN(LOC) \ + ((expand_location_to_expansion_point (LOC)).column) + + #define input_line LOCATION_LINE (input_location) #define input_filename LOCATION_FILE (input_location) #define in_system_header_at(LOC) \