diff mbox

Avoid double unread_char (c) in patch 8a of RTL frontend

Message ID 1481166119-45975-1-git-send-email-dmalcolm@redhat.com
State New
Headers show

Commit Message

David Malcolm Dec. 8, 2016, 3:01 a.m. UTC
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(-)

Comments

Bernd Schmidt Dec. 8, 2016, 3:16 p.m. UTC | #1
On 12/08/2016 04:01 AM, David Malcolm wrote:
> 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.

For avoidance of doubt, ok to check in the currently approved patches 
with this change as well.
>
> -  unread_char (c);
> -  *out_loc = get_current_location ();
> -  read_char ();

Might be worth trying to look for this pattern in other parts of the 
patch kit to see if it can be replaced.


Bernd
diff mbox

Patch

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;