The RTL frontend patch kit failed to build on powerpc-ibm-aix7.1.3.0
(gcc111), with this error:

build/genmddeps ../../src/gcc/common.md ../../src/gcc/config/rs6000/rs6000.md > 
tmp-mddeps
../../src/gcc/config/rs6000/rs6000.md:2255:1: unterminated construct

due to the final close paren on line 2259 of rs6000.md:

  2259          (and:GPR (match_dup 1)

not being detected by read_skip_construct.

Bisecting the patch kit, it appears to be due to this hunk in patch 8a:

@@ -463,8 +481,12 @@ md_reader::read_name (struct md_name *name)
       c = read_char ();
     }

+  unread_char (c);
+  *out_loc = get_current_location ();
+  read_char ();
+

It appears that this can lead to unread_char (c) being called twice
for the same c, followed by a read_char () (i.e. the 2nd call to
unread_char passes the wrong character back).  Given that unread_char
is a wrapper around libc's ungetc, I *think* this is showing up a
difference between glibc and AIX's libc implementation (and possibly
a reliance on undefined behavior).

The attached tweak to patch 8a simplifies the function, eliminating
these calls, by using the start of the name for the location, rather
than the end.

It fixes the build of the kit on powerpc-ibm-aix7.1.3.0
(and continues to build correctly on x86_64-pc-linux-gnu).

gcc/ChangeLog:
        * read-md.c (md_reader::read_name_1): Write out the location of
        the start of the name, rather than the end, eliminating
        unread_char and read_char calls.
---
 gcc/read-md.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/gcc/read-md.c b/gcc/read-md.c
index e581326..ad61cdd 100644
--- a/gcc/read-md.c
+++ b/gcc/read-md.c
@@ -461,6 +461,8 @@ md_reader::read_name_1 (struct md_name *name, file_location 
*out_loc)
 
   c = read_skip_spaces ();
 
+  *out_loc = get_current_location ();
+
   i = 0;
   angle_bracket_depth = 0;
   while (1)
@@ -491,10 +493,6 @@ md_reader::read_name_1 (struct md_name *name, 
file_location *out_loc)
       c = read_char ();
     }
 
-  unread_char (c);
-  *out_loc = get_current_location ();
-  read_char ();
-
   if (i == 0)
     return false;
 
-- 
1.8.5.3

Reply via email to