From patchwork Fri Nov 11 21:15:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 693957 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 3tFsQv1xQ4z9t2D for ; Sat, 12 Nov 2016 07:46:47 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="mLIAEC1I"; dkim-atps=neutral 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:in-reply-to:references; q=dns; s= default; b=EwZrGEdQMvxK/+2kkplD4UA+Cmes1SiBUhHaF3dQ80ql7HLQ/edwd qZqi3sdgkZqdsAkrpNd5Z5RKIe3bsyHKU+LWhatjw2T/ZcufP2WcYTfs8IHk5LIs NKS/hv+FNUcb/oZ0eqrY6/WtUimEd/T4TWSwmlobUklKf++OK49xvM= 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:in-reply-to:references; s= default; bh=szeC55rVm0+KJdM6/Dq7yR4J6QQ=; b=mLIAEC1IolAQJaEYisn1 veWerWWfLoK8CpFMZGzp/aK3P4WWI35vWgetPE+LZjxtXSmfHSbV0lhfdhW9vn7b EPyXRPL8b4SAbPYsBWulLhJ/J1JZwaCd6P7emdolD8vr0BG3P/997gWfXnx3V+1E W/G8njMJ9pizebQUjh0uBdo= Received: (qmail 20011 invoked by alias); 11 Nov 2016 20:44:01 -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 19234 invoked by uid 89); 11 Nov 2016 20:43:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.2 spammy=tracked, Sandiford, sandiford, subsystem X-HELO: eggs.gnu.org Received: from eggs.gnu.org (HELO eggs.gnu.org) (208.118.235.92) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 11 Nov 2016 20:43:48 +0000 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c5Ifm-0005a7-Ii for gcc-patches@gcc.gnu.org; Fri, 11 Nov 2016 15:43:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60762) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c5Ifm-0005Zy-Ad for gcc-patches@gcc.gnu.org; Fri, 11 Nov 2016 15:43:42 -0500 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 90CA6C057FA7 for ; Fri, 11 Nov 2016 20:43:41 +0000 (UTC) Received: from c64.redhat.com (vpn-225-220.phx2.redhat.com [10.3.225.220]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uABKhZ1R019499; Fri, 11 Nov 2016 15:43:41 -0500 From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 7/9] Add RTL-error-handling to host Date: Fri, 11 Nov 2016 16:15:33 -0500 Message-Id: <1478898935-46932-8-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1478898935-46932-1-git-send-email-dmalcolm@redhat.com> References: <1478898935-46932-1-git-send-email-dmalcolm@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-IsSubscribed: yes Link to previous discussion: https://gcc.gnu.org/ml/gcc-patches/2016-10/msg00648.html On Mon, 2016-10-10 at 19:53 +0100, Richard Sandiford wrote: > David Malcolm writes: > > On Wed, 2016-10-05 at 18:00 +0200, Bernd Schmidt wrote: > > > On 10/05/2016 06:15 PM, David Malcolm wrote: > > > > * errors.c: Use consistent pattern for bconfig.h vs > > > > config.h > > > > includes. > > > > (progname): Wrap with #ifdef GENERATOR_FILE. > > > > (error): Likewise. Add "error: " to message. > > > > (fatal): Likewise. > > > > (internal_error): Likewise. > > > > (trim_filename): Likewise. > > > > (fancy_abort): Likewise. > > > > * errors.h (struct file_location): Move here from read > > > > -md.h. > > > > (file_location::file_location): Likewise. > > > > (error_at): New decl. > > > > > > Can you split these out into a separate patch as well? I'll > > > require > > > more > > > explanation for them and they seem largely independent. > > > > [CCing Richard Sandiford] > > > > The gen* tools have their own diagnostics system, in errors.c: > > > > /* warning, error, and fatal. These definitions are suitable for > > use > > in the generator programs; the compiler has a more elaborate > > suite > > of diagnostic printers, found in diagnostic.c. */ > > > > with file locations tracked using read-md.h's struct file_location, > > rather than location_t (aka libcpp's source_location). > > > > Implementing an RTL frontend by using the RTL reader from read > > -rtl.c > > means that we now need a diagnostics subsystem on the *host* for > > handling errors in RTL files, rather than just on the build > > machine. > > > > There seem to be two ways to do this: > > > > (A) build the "light" diagnostics system (errors.c) for the host > > as > > well as build machine, and link it with the RTL reader there, so > > there > > are two parallel diagnostics subsystems. > > > > (B) build the "real" diagnostics system (diagnostics*) for the > > *build* machine as well as the host, and use it from the gen* > > tools, > > eliminating the "light" system, and porting the gen* tools to use > > libcpp for location tracking. > > > > Approach (A) seems to be simpler, which is what this part of the > > patch > > does. > > > > I've experimented with approach (B). I think it's doable, but it's > > much more invasive (perhaps needing a libdiagnostics.a and a > > build/libdiagnostics.a in gcc/Makefile.in), so I hope this can be > > followup work. > > > > I can split the relevant parts out into a separate patch, but I was > > wondering if either of you had a strong opinion on (A) vs (B) > > before I > > do so? > > (A) sounds fine to me FWIW. And sorry for the slow reply. > > Thanks, > Richard This patch implements approach (A). It updates the error messages to contain "error: " so that they can be handled by DejaGnu. It also adds an "error_at" function to the "light" API. Doing so requires moving the decl of struct file_location to errors.h. gcc/ChangeLog: * Makefile.in (OBJS): Add errors.o. * errors.c: Use consistent pattern for bconfig.h vs config.h includes. (progname): Wrap with #ifdef GENERATOR_FILE. (error): Likewise. Add "error: " to message. (fatal): Likewise. (internal_error): Likewise. (trim_filename): Likewise. (fancy_abort): Likewise. * errors.h (struct file_location): Move here from read-md.h. (file_location::file_location): Likewise. (error_at): New decl. * read-md.h (struct file_location): Move to errors.h. (file_location::file_location): Likewise. Include errors.h. --- gcc/Makefile.in | 1 + gcc/errors.c | 23 +++++++++++++++++------ gcc/errors.h | 14 ++++++++++++++ gcc/read-md.h | 14 +------------- 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/gcc/Makefile.in b/gcc/Makefile.in index fa54215..c265893 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -1266,6 +1266,7 @@ OBJS = \ dwarf2cfi.o \ dwarf2out.o \ emit-rtl.o \ + errors.o \ et-forest.o \ except.o \ explow.o \ diff --git a/gcc/errors.c b/gcc/errors.c index 468384c..8df94ab 100644 --- a/gcc/errors.c +++ b/gcc/errors.c @@ -21,18 +21,21 @@ along with GCC; see the file COPYING3. If not see in the generator programs; the compiler has a more elaborate suite of diagnostic printers, found in diagnostic.c. */ -#ifdef HOST_GENERATOR_FILE -#include "config.h" -#define GENERATOR_FILE 1 -#else +/* This file is compiled twice: once for the generator programs + once for the compiler. */ +#ifdef GENERATOR_FILE #include "bconfig.h" +#else +#include "config.h" #endif #include "system.h" #include "errors.h" /* Set this to argv[0] at the beginning of main. */ +#ifdef GENERATOR_FILE const char *progname; +#endif /* #ifdef GENERATOR_FILE */ /* Starts out 0, set to 1 if error is called. */ @@ -55,13 +58,15 @@ warning (const char *format, ...) /* Print an error message - we keep going but the output is unusable. */ +#ifdef GENERATOR_FILE + void error (const char *format, ...) { va_list ap; va_start (ap, format); - fprintf (stderr, "%s: ", progname); + fprintf (stderr, "%s: error: ", progname); vfprintf (stderr, format, ap); va_end (ap); fputc ('\n', stderr); @@ -69,6 +74,7 @@ error (const char *format, ...) have_error = 1; } +#endif /* #ifdef GENERATOR_FILE */ /* Fatal error - terminate execution immediately. Does not return. */ @@ -78,7 +84,7 @@ fatal (const char *format, ...) va_list ap; va_start (ap, format); - fprintf (stderr, "%s: ", progname); + fprintf (stderr, "%s: error: ", progname); vfprintf (stderr, format, ap); va_end (ap); fputc ('\n', stderr); @@ -87,6 +93,8 @@ fatal (const char *format, ...) /* Similar, but say we got an internal error. */ +#ifdef GENERATOR_FILE + void internal_error (const char *format, ...) { @@ -127,8 +135,11 @@ trim_filename (const char *name) /* "Fancy" abort. Reports where in the compiler someone gave up. This file is used only by build programs, so we're not as polite as the version in diagnostic.c. */ + void fancy_abort (const char *file, int line, const char *func) { internal_error ("abort in %s, at %s:%d", func, trim_filename (file), line); } + +#endif /* #ifdef GENERATOR_FILE */ diff --git a/gcc/errors.h b/gcc/errors.h index a6973f3..ebafa77 100644 --- a/gcc/errors.h +++ b/gcc/errors.h @@ -28,8 +28,22 @@ along with GCC; see the file COPYING3. If not see #ifndef GCC_ERRORS_H #define GCC_ERRORS_H +/* Records a position in the file. */ +struct file_location { + file_location () {} + file_location (const char *, int, int); + + const char *filename; + int lineno; + int colno; +}; + +inline file_location::file_location (const char *filename_in, int lineno_in, int colno_in) +: filename (filename_in), lineno (lineno_in), colno (colno_in) {} + extern void warning (const char *, ...) ATTRIBUTE_PRINTF_1 ATTRIBUTE_COLD; extern void error (const char *, ...) ATTRIBUTE_PRINTF_1 ATTRIBUTE_COLD; +extern void error_at (file_location, const char *, ...) ATTRIBUTE_PRINTF_2 ATTRIBUTE_COLD; extern void fatal (const char *, ...) ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF_1 ATTRIBUTE_COLD; extern void internal_error (const char *, ...) ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF_1 ATTRIBUTE_COLD; extern const char *trim_filename (const char *); diff --git a/gcc/read-md.h b/gcc/read-md.h index 27fc9c2..8910b75 100644 --- a/gcc/read-md.h +++ b/gcc/read-md.h @@ -21,19 +21,7 @@ along with GCC; see the file COPYING3. If not see #define GCC_READ_MD_H #include "obstack.h" - -/* Records a position in the file. */ -struct file_location { - file_location () {} - file_location (const char *, int, int); - - const char *filename; - int lineno; - int colno; -}; - -inline file_location::file_location (const char *filename_in, int lineno_in, int colno_in) -: filename (filename_in), lineno (lineno_in), colno (colno_in) {} +#include "errors.h" /* Holds one symbol or number in the .md file. */ struct md_name {