From patchwork Tue Jul 19 08:16:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georg-Johann Lay X-Patchwork-Id: 649987 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 3rttDX03d7z9s5J for ; Tue, 19 Jul 2016 18:16:43 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=s9qTVdIa; 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 :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=p+yGsg981vgWd7vaz OZjwwMW91kGUuL9T6cayyaF5MJGJh2lRxXupTRofKFVVmRyWy4ISPSax7Ywi3i9x y/RMO7Ib7M/8zQR2GvdSWdng2fAhpAsOasUFuI1FfTZPZmdJtDp7GMeh/lCicvfa Q6nCurZLa7z4DhASwM+Oq21/Rk= 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:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=QIYmnnVB4FEp3J7y6KZqdHo GKvg=; b=s9qTVdIa9amd/VNrxiBGYF5etMBN2vwouSpPZV2vrhQw6q6xKAJBKgs iaNqMzy3sOHzDutjes9C4ehRk7t8ZBsfHvHeafbCUtUG7ewMcS7qRDrxG8POgkbY IZIKTtsLmIM034g1mFjlFvTozHZkjjO6rF1Z+Fdjr2FD71qoC29Y= Received: (qmail 31047 invoked by alias); 19 Jul 2016 08:16:35 -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 31038 invoked by uid 89); 19 Jul 2016 08:16:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL, BAYES_00, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 spammy=Attached, miscellaneous, Named X-HELO: mo4-p00-ob.smtp.rzone.de Received: from mo4-p00-ob.smtp.rzone.de (HELO mo4-p00-ob.smtp.rzone.de) (81.169.146.160) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 19 Jul 2016 08:16:24 +0000 X-RZG-AUTH: :LXoWVUeid/7A29J/hMvvT3ol15ykJcYwR/bcHRirORRW3yMcVao= X-RZG-CLASS-ID: mo00 Received: from [192.168.0.123] (mail.hightec-rt.com [213.135.1.215]) by smtp.strato.de (RZmta 38.13 DYNA|AUTH) with ESMTPSA id z019b9s6J8GCaVy (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Tue, 19 Jul 2016 10:16:12 +0200 (CEST) Subject: Re: [patch] Add new hook to diagnose address space usage (take #2) To: Bernd Schmidt References: <051d5d94-6175-0b11-04ee-439f0cab870a@gjlay.de> Cc: GCC Patches From: Georg-Johann Lay Message-ID: <7bfc1c40-df78-895f-618e-ec83d73864cd@gjlay.de> Date: Tue, 19 Jul 2016 10:16:11 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: X-IsSubscribed: yes On 18.07.2016 16:13, Bernd Schmidt wrote: > On 07/14/2016 05:11 PM, Georg-Johann Lay wrote: >> The hook allows better diagnostics: The address spaces are registered >> with c_register_addr_space and if the parser comes across an address >> space it provides the hook with the needed information, in particular >> the location of the token so that the message would be something like > > Looks reasonable, except... > >> +(diagnose_usage, >> + "Define this hook if the availability of an address space depends on\n\ >> +command line options and some diagnostics shall be printed when the\n\ > > "should", not "shall", I think. Fixed. >> +bool >> +default_addr_space_diagnose_usage (addr_space_t ARG_UNUSED (as), >> + location_t ARG_UNUSED (loc)) >> +{ >> + return false; >> +} > > The return value is not used, so it should return void. That would also match > the documentation you added (which says "does nothing" rather than "returns > false"). Fixed, the hook returns void now. The idea was that in a future version the c-parser might take decision depending on whether an error has been issued. > Remove unused arg names in default hook implementations, I think. > > > Bernd > Done. Attached is the updated version of the change, log entry is the same as before. Johann gcc/ * target.def (addr_space): Add new diagnose_usage to hook vector. * targhooks.c (default_addr_space_diagnose_usage): Add default implementation and... * targhooks.h (default_addr_space_diagnose_usage): ... its prototype. * c/c-parser.c (c_lex_one_token) [CPP_NAME]: If the token is some address space, call targetm.addr_space.diagnose_usage. * doc/tm.texi.in (Named Address Spaces): Add anchor for TARGET_ADDR_SPACE_DIAGNOSE_USAGE documentation. * doc/tm.texi: Regenerate. Index: c/c-parser.c =================================================================== --- c/c-parser.c (revision 238425) +++ c/c-parser.c (working copy) @@ -301,6 +301,9 @@ c_lex_one_token (c_parser *parser, c_tok else if (rid_code >= RID_FIRST_ADDR_SPACE && rid_code <= RID_LAST_ADDR_SPACE) { + addr_space_t as; + as = (addr_space_t) (rid_code - RID_FIRST_ADDR_SPACE); + targetm.addr_space.diagnose_usage (as, token->location); token->id_kind = C_ID_ADDRSPACE; token->keyword = rid_code; break; Index: doc/tm.texi =================================================================== --- doc/tm.texi (revision 238425) +++ doc/tm.texi (working copy) @@ -10431,6 +10431,17 @@ Define this to define how the address sp The result is the value to be used with @code{DW_AT_address_class}. @end deftypefn +@deftypefn {Target Hook} void TARGET_ADDR_SPACE_DIAGNOSE_USAGE (addr_space_t @var{as}, location_t @var{loc}) +Define this hook if the availability of an address space depends on +command line options and some diagnostics should be printed when the +address space is used. This hook is called during parsing and allows +to emit a better diagnostic compared to the case where the address space +was not registered with @code{c_register_addr_space}. @var{as} is +the address space as registered with @code{c_register_addr_space}. +@var{loc} is the location of the address space qualifier token. +The default implementation does nothing. +@end deftypefn + @node Misc @section Miscellaneous Parameters @cindex parameters, miscellaneous Index: doc/tm.texi.in =================================================================== --- doc/tm.texi.in (revision 238425) +++ doc/tm.texi.in (working copy) @@ -7486,6 +7486,8 @@ c_register_addr_space ("__ea", ADDR_SPAC @hook TARGET_ADDR_SPACE_DEBUG +@hook TARGET_ADDR_SPACE_DIAGNOSE_USAGE + @node Misc @section Miscellaneous Parameters @cindex parameters, miscellaneous Index: target.def =================================================================== --- target.def (revision 238425) +++ target.def (working copy) @@ -3241,6 +3241,20 @@ The result is the value to be used with int, (addr_space_t as), default_addr_space_debug) +/* Function to emit custom diagnostic if an address space is used. */ +DEFHOOK +(diagnose_usage, + "Define this hook if the availability of an address space depends on\n\ +command line options and some diagnostics should be printed when the\n\ +address space is used. This hook is called during parsing and allows\n\ +to emit a better diagnostic compared to the case where the address space\n\ +was not registered with @code{c_register_addr_space}. @var{as} is\n\ +the address space as registered with @code{c_register_addr_space}.\n\ +@var{loc} is the location of the address space qualifier token.\n\ +The default implementation does nothing.", + void, (addr_space_t as, location_t loc), + default_addr_space_diagnose_usage) + HOOK_VECTOR_END (addr_space) #undef HOOK_PREFIX Index: targhooks.c =================================================================== --- targhooks.c (revision 238425) +++ targhooks.c (working copy) @@ -1291,6 +1291,15 @@ default_addr_space_debug (addr_space_t a return as; } +/* The default hook implementation for TARGET_ADDR_SPACE_DIAGNOSE_USAGE. + Don't complain about any address space. */ + +void +default_addr_space_diagnose_usage (addr_space_t, location_t) +{ +} + + /* The default hook for TARGET_ADDR_SPACE_CONVERT. This hook should never be called for targets with only a generic address space. */ Index: targhooks.h =================================================================== --- targhooks.h (revision 238425) +++ targhooks.h (working copy) @@ -181,6 +181,7 @@ extern rtx default_addr_space_legitimize extern bool default_addr_space_subset_p (addr_space_t, addr_space_t); extern bool default_addr_space_zero_address_valid (addr_space_t); extern int default_addr_space_debug (addr_space_t); +extern void default_addr_space_diagnose_usage (addr_space_t, location_t); extern rtx default_addr_space_convert (rtx, tree, tree); extern unsigned int default_case_values_threshold (void); extern bool default_have_conditional_execution (void);