public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 1/4] Hack: non-symbolic numeric constant warning
@ 2016-09-01 21:33 Segher Boessenkool
  2016-09-01 21:33 ` [PATCH 3/4] rs6000: Rename 109 -> VRSAVE_REGNO Segher Boessenkool
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Segher Boessenkool @ 2016-09-01 21:33 UTC (permalink / raw)
  To: gcc-patches; +Cc: dje.gcc, Segher Boessenkool

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-09-01 21:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-01 21:33 [PATCH 1/4] Hack: non-symbolic numeric constant warning Segher Boessenkool
2016-09-01 21:33 ` [PATCH 3/4] rs6000: Rename 109 -> VRSAVE_REGNO Segher Boessenkool
2016-09-01 21:33 ` [PATCH 2/4] rs6000: Rename 74 -> CR6_REGNO Segher Boessenkool
2016-09-01 21:33 ` [PATCH 4/4] rs6000: Rename 110 -> VSCR_REGNO Segher Boessenkool

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).