diff mbox

[1/4] Hack: non-symbolic numeric constant warning

Message ID edfc2fc437d5d6559febaf2260f6415a57b474b7.1472764438.git.segher@kernel.crashing.org
State New
Headers show

Commit Message

Segher Boessenkool Sept. 1, 2016, 9:32 p.m. UTC
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 mbox

Patch

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;