[binutils-gdb] Allow integer contants to have a U suffix. Improve error reporting for missing closing parentheses.

Nick Clifton nickc@sourceware.org
Thu Apr 7 11:35:00 GMT 2016


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=e140100a5da85568e83ffe8e77d3f5e4a59ddee8

commit e140100a5da85568e83ffe8e77d3f5e4a59ddee8
Author: Nick Clifton <nickc@redhat.com>
Date:   Thu Apr 7 12:34:06 2016 +0100

    Allow integer contants to have a U suffix.  Improve error reporting for missing closing parentheses.
    
    	PR gas/19910
    	* config/tc-sparc.c (sparc_ip): Report an error if the expression
    	inside a %-macro could not be fully parsed.
    	* expr.c (integer_constant): Accept and ignore U suffixes to
    	integers.
    	(operand): When a missing closing parenthesis is encountered,
    	report the character that was found instead.
    	* testsuite/gas/mips/tls-ill.l: Update expected error message.
    	* testsuite/gas/sparc/pr19910-1.d: New test driver.
    	* testsuite/gas/sparc/pr19910-1.s: New test.
    	* testsuite/gas/sparc/pr19910-2.l: Expected error output.
    	* testsuite/gas/sparc/pr19910-2.s: New test.
    	* testsuite/gas/sparc/sparc.exp: Run the new tests.

Diff:
---
 gas/ChangeLog                       | 16 ++++++++++++++++
 gas/config/tc-sparc.c               |  5 +++++
 gas/expr.c                          | 15 ++++++++++++++-
 gas/testsuite/gas/mips/tls-ill.l    |  4 ++--
 gas/testsuite/gas/sparc/pr19910-1.d | 10 ++++++++++
 gas/testsuite/gas/sparc/pr19910-1.s |  8 ++++++++
 gas/testsuite/gas/sparc/pr19910-2.l |  4 ++++
 gas/testsuite/gas/sparc/pr19910-2.s |  5 +++++
 gas/testsuite/gas/sparc/sparc.exp   |  3 +++
 9 files changed, 67 insertions(+), 3 deletions(-)

diff --git a/gas/ChangeLog b/gas/ChangeLog
index 8647d9e..91f1780 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,19 @@
+2016-04-07  Nick Clifton  <nickc@redhat.com>
+
+	PR gas/19910
+	* config/tc-sparc.c (sparc_ip): Report an error if the expression
+	inside a %-macro could not be fully parsed.
+	* expr.c (integer_constant): Accept and ignore U suffixes to
+	integers.
+	(operand): When a missing closing parenthesis is encountered,
+	report the character that was found instead.
+	* testsuite/gas/mips/tls-ill.l: Update expected error message.
+	* testsuite/gas/sparc/pr19910-1.d: New test driver.
+	* testsuite/gas/sparc/pr19910-1.s: New test.
+	* testsuite/gas/sparc/pr19910-2.l: Expected error output.
+	* testsuite/gas/sparc/pr19910-2.s: New test.
+	* testsuite/gas/sparc/sparc.exp: Run the new tests.
+
 2016-04-06  Nick Clifton  <nickc@redhat.com>
 
 	* config/tc-msp430.c (msp430_operands): Check for a NOP preceding
diff --git a/gas/config/tc-sparc.c b/gas/config/tc-sparc.c
index 9526583..a51ca1f 100644
--- a/gas/config/tc-sparc.c
+++ b/gas/config/tc-sparc.c
@@ -2626,6 +2626,11 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 		    *s1 = '\0';
 		    (void) get_expression (s);
 		    *s1 = ')';
+		    if (expr_end != s1)
+		      {
+			as_bad (_("Expression inside %%%s could not be parsed"), op_arg);
+			return special_case;
+		      }
 		    s = s1 + 1;
 		    if (*s == ',' || *s == ']' || !*s)
 		      continue;
diff --git a/gas/expr.c b/gas/expr.c
index c6c730e..afe46c4 100644
--- a/gas/expr.c
+++ b/gas/expr.c
@@ -508,6 +508,13 @@ integer_constant (int radix, expressionS *expressionP)
       && input_line_pointer - 1 == suffix)
     c = *input_line_pointer++;
 
+#ifndef tc_allow_U_suffix
+#define tc_allow_U_suffix 1
+#endif
+  /* PR 19910: Look for, and ignore, a U suffix to the number.  */
+  if (tc_allow_U_suffix && (c == 'U' || c == 'u'))
+    c = * input_line_pointer++;
+
   if (small)
     {
       /* Here with number, in correct radix. c is the next char.
@@ -950,7 +957,13 @@ operand (expressionS *expressionP, enum expr_mode mode)
       /* expression () will pass trailing whitespace.  */
       if ((c == '(' && *input_line_pointer != ')')
 	  || (c == '[' && *input_line_pointer != ']'))
-	as_bad (_("missing '%c'"), c == '(' ? ')' : ']');
+	{
+	  if (* input_line_pointer)
+	    as_bad (_("found '%c', expected: '%c'"),
+		    * input_line_pointer, c == '(' ? ')' : ']');
+	  else
+	    as_bad (_("missing '%c'"), c == '(' ? ')' : ']');
+	}	    
       else
 	input_line_pointer++;
       SKIP_WHITESPACE ();
diff --git a/gas/testsuite/gas/mips/tls-ill.l b/gas/testsuite/gas/mips/tls-ill.l
index 8085f82..0057bd1 100644
--- a/gas/testsuite/gas/mips/tls-ill.l
+++ b/gas/testsuite/gas/mips/tls-ill.l
@@ -4,8 +4,8 @@
 .*:7: Error: bad expression
 .*:7: Error: invalid operands `addiu \$4,\$28,%tprel\(tlsvar\)'
 .*:8: Error: bad expression
-.*:8: Error: missing '\)'
+.*:8: Error: found 'g', expected: '\)'
 .*:8: Error: invalid operands `addiu \$4,\$28,%lo\(%gottprel\(tlsvar\)\)'
 .*:9: Error: bad expression
-.*:9: Error: missing '\)'
+.*:9: Error: found 'g', expected: '\)'
 .*:9: Error: invalid operands `addiu \$4,\$28,%hi\(%gottprel\(tlsvar\)\)'
diff --git a/gas/testsuite/gas/sparc/pr19910-1.d b/gas/testsuite/gas/sparc/pr19910-1.d
new file mode 100644
index 0000000..10874e9
--- /dev/null
+++ b/gas/testsuite/gas/sparc/pr19910-1.d
@@ -0,0 +1,10 @@
+#as: 
+#objdump: -dr --prefix-addresses
+#name: PR19910 - make sure that U suffix is accepted
+
+.*: +file format .*
+
+Disassembly of section .text:
+0x0+000 sethi[ 	]+%hi\(0x4000\), %g1
+0x0+004 mov[ 	]+0x40, %g1
+0x0+008 mov[ 	]+4, %g1
diff --git a/gas/testsuite/gas/sparc/pr19910-1.s b/gas/testsuite/gas/sparc/pr19910-1.s
new file mode 100644
index 0000000..07e8ce0
--- /dev/null
+++ b/gas/testsuite/gas/sparc/pr19910-1.s
@@ -0,0 +1,8 @@
+	# U suffix should not trigger an error.
+	sethi %hi(0x4000U), %g1
+
+	# U suffix should not prevent evaluation of the expression.
+        or %g0, %lo(0x400U + 0x40U), %g1
+
+	# U suffix should not confuse multiple layers of parentheses.
+        or %g0, %lo((0x4000U + 0x4U)), %g1
diff --git a/gas/testsuite/gas/sparc/pr19910-2.l b/gas/testsuite/gas/sparc/pr19910-2.l
new file mode 100644
index 0000000..8c8f778
--- /dev/null
+++ b/gas/testsuite/gas/sparc/pr19910-2.l
@@ -0,0 +1,4 @@
+.*pr19910-2.s: Assembler messages:
+.*pr19910-2.s:2: Error: Expression inside %hi could not be parsed
+.*pr19910-2.s:5: Error: found 'V', expected: '\)'
+.*pr19910-2.s:5: Error: Expression inside %lo could not be parsed
diff --git a/gas/testsuite/gas/sparc/pr19910-2.s b/gas/testsuite/gas/sparc/pr19910-2.s
new file mode 100644
index 0000000..e694006
--- /dev/null
+++ b/gas/testsuite/gas/sparc/pr19910-2.s
@@ -0,0 +1,5 @@
+	# Mistyping V instead of U should trigger an error message
+	sethi %hi(0x4000V), %g1
+
+	# A different error can be expected when there are multiple layers of parentheses.
+        or %g0, %lo((0x4000V + 0x4U)), %g1
diff --git a/gas/testsuite/gas/sparc/sparc.exp b/gas/testsuite/gas/sparc/sparc.exp
index d7d6396..3e7cc4c 100644
--- a/gas/testsuite/gas/sparc/sparc.exp
+++ b/gas/testsuite/gas/sparc/sparc.exp
@@ -97,6 +97,9 @@ if [istarget sparc*-*-*] {
     run_dump_test "natural-32"
 
     run_list_test "pr4587" ""
+
+    run_dump_test "pr19910-1"
+    run_list_test "pr19910-2"
 }
 
 if [istarget sparc-*-vxworks*] {



More information about the Binutils-cvs mailing list