From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29605 invoked by alias); 1 Sep 2016 21:33:24 -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 29593 invoked by uid 89); 1 Sep 2016 21:33:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD,T_FILL_THIS_FORM_SHORT autolearn=ham version=3.3.2 spammy=Hx-languages-length:2422 X-HELO: gcc1-power7.osuosl.org Received: from gcc1-power7.osuosl.org (HELO gcc1-power7.osuosl.org) (140.211.15.137) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 01 Sep 2016 21:33:22 +0000 Received: by gcc1-power7.osuosl.org (Postfix, from userid 10019) id EA4011C06F4; Thu, 1 Sep 2016 21:33:16 +0000 (UTC) From: Segher Boessenkool To: gcc-patches@gcc.gnu.org Cc: dje.gcc@gmail.com, Segher Boessenkool Subject: [PATCH 1/4] Hack: non-symbolic numeric constant warning Date: Thu, 01 Sep 2016 21:33:00 -0000 Message-Id: X-IsSubscribed: yes X-SW-Source: 2016-09/txt/msg00065.txt.bz2 This patch prints a warning if a register number in the machine description patterns is non-symbolic, to catch places that should use a constant from a define_constants instead (e.g., LR_REGNO). I hardcoded this to not warn for regno < 32, i.e. the GPRs on PowerPC. That of course is not acceptable like this. If anyone wants to pick this up and make that a target check, feel free :-) (The global variable is not so hot either). The next three patches in the series are what this patch uncovered; I'll commit those to trunk. Segher --- gcc/read-md.c | 15 +++++++++++++++ gcc/read-md.h | 3 +++ gcc/read-rtl.c | 2 ++ 3 files changed, 20 insertions(+) diff --git a/gcc/read-md.c b/gcc/read-md.c index b422d8d..7f5cdaf 100644 --- a/gcc/read-md.c +++ b/gcc/read-md.c @@ -94,6 +94,9 @@ static htab_t enum_types; static void handle_file (directive_handler_t); +/* For read_name: print a message if a number is non-symbolic. */ +int warn_if_non_symbolic_number; + /* Given an object that starts with a char * name field, return a hash code for its name. */ @@ -450,6 +453,18 @@ read_name (struct md_name *name) name->buffer[i] = 0; name->string = name->buffer; + if (warn_if_non_symbolic_number) + { + const char *p = name->string; + while (*p && ISSPACE (*p)) + p++; + if ((ISDIGIT (*p) || *p == '-' || *p == '+') && atoi (p) >= 32) + { + file_location loc (read_md_filename, read_md_lineno); + message_at (loc, "numeric constant %s is a plain number", p); + } + } + if (md_constants) { /* Do constant expansion. */ diff --git a/gcc/read-md.h b/gcc/read-md.h index fa25951..6f9c34e 100644 --- a/gcc/read-md.h +++ b/gcc/read-md.h @@ -103,6 +103,9 @@ extern const char *read_md_filename; extern struct obstack string_obstack; extern void (*include_callback) (const char *); +/* For read_name: print a message if a number is non-symbolic. */ +extern int warn_if_non_symbolic_number; + /* Read the next character from the MD file. */ static inline int diff --git a/gcc/read-rtl.c b/gcc/read-rtl.c index 4614e35..14e53cf 100644 --- a/gcc/read-rtl.c +++ b/gcc/read-rtl.c @@ -1311,7 +1311,9 @@ read_rtx_code (const char *code_name) break; case 'r': + warn_if_non_symbolic_number = 1; read_name (&name); + warn_if_non_symbolic_number = 0; validate_const_int (name.string); set_regno_raw (return_rtx, atoi (name.string), 1); REG_ATTRS (return_rtx) = NULL; -- 1.9.3