This is the mail archive of the binutils@sourceware.cygnus.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

expression parsing with odd line separator char


The hppa assembler uses `!' as the line separator char, which causes some
problems when parsing expressions.  eg.

$ cat > t5.s
 .text ! nop
$ hppa1.1-linux-as -o t5.o t5.s
t5.s: Assembler messages:
t5.s:1: Error: bad or irreducible absolute expression; zero assumed

The following patch to expr.c fixes this problem.  I've also changed
is_end_of_line to not set the default `;' entry (or `!' for TC_HPPA), as
these will be set from line_separator_chars in read_begin.  is_end_of_line
now just uses 0 or 1, rather than the unusual 99 value.  I assume this
was done originally to differentiate the default values from those set in
read_begin, however there is no place that tests for anything besides 0 or
!0.  While checking all these references, I found a number of places that
used a (possibly signed) char index.

OK to install to the trunk?  I'm not proposing this go on the 2.10 branch,
as there may be some consequence of the expr.c change I haven't foreseen..

Regards, Alan Modra
-- 
Linuxcare.  Support for the Revolution.

gas/ChangeLog
	* expr.c (operand): Test is_end_of_line outside switch to catch
	line separator chars that are also operators.
	(operator): Return O_illegal for line separator chars.

	* read.c (is_end_of_line): Use 1 instead of 99.  Don't set `;'
	entry (or `!' entry for TC_HPPA).

	* config/tc-arm.c (my_get_float_expression): Cast to unsigned char
	before indexing is_end_of_line.  Remove redundant check for '\0'.
	(fp_op2): Likewise.
	* config/tc-h8500.c (md_assemble): Likewise.
	* config/tc-mcore.c (md_assemble): Likewise.
	* config/tc-tic30.c (tic30_find_parallel_insn): Likewise.
	(md_atof): Likewise

	* config/tc-m88k.c (s_bss): Cast to unsigned char before indexing
	is_end_of_line.
	* config/tc-mcore.c (mcore_cons): Likewise.
	(mcore_float_cons): Likewise.
	(mcore_stringer): Likewise.
	* config/tc-tic30.c (tic30_find_parallel_insn): Likewise.

Index: gas/expr.c
===================================================================
RCS file: /cvs/src/src/gas/expr.c,v
retrieving revision 1.15
diff -u -p -r1.15 expr.c
--- expr.c	2000/04/21 20:22:22	1.15
+++ expr.c	2000/05/31 07:01:42
@@ -799,6 +799,9 @@ operand (expressionP)
   SKIP_WHITESPACE ();		/* leading whitespace is part of operand. */
   c = *input_line_pointer++;	/* input_line_pointer->past char in c. */
 
+  if (is_end_of_line[(unsigned char) c])
+    goto eol;
+
   switch (c)
     {
     case '1':
@@ -1166,9 +1169,8 @@ operand (expressionP)
 	{
 	  goto isname;
 	}
+
     case ',':
-    case '\n':
-    case '\0':
     eol:
       /* can't imagine any other kind of operand */
       expressionP->X_op = O_absent;
@@ -1211,8 +1213,6 @@ operand (expressionP)
 #ifdef TC_M68K
     de_fault:
 #endif
-      if (is_end_of_line[(unsigned char) c])
-	goto eol;
       if (is_name_beginner (c))	/* here if did not begin with a digit */
 	{
 	  /*
@@ -1570,6 +1570,9 @@ operator ()
   operatorT ret;
 
   c = *input_line_pointer & 0xff;
+
+  if (is_end_of_line[c])
+    return O_illegal;
 
   switch (c)
     {
Index: gas/read.c
===================================================================
RCS file: /cvs/src/src/gas/read.c,v
retrieving revision 1.19
diff -u -p -r1.19 read.c
--- read.c	2000/04/21 20:22:22	1.19
+++ read.c	2000/05/31 07:02:11
@@ -146,33 +146,26 @@ char lex_type[256] =
  * In: a character.
  * Out: 1 if this character ends a line.
  */
-#define Z_ (0)
 char is_end_of_line[256] =
 {
 #ifdef CR_EOL
-  99, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, 99, Z_, Z_, 99, Z_, Z_,	/* @abcdefghijklmno */
+  1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0,	/* @abcdefghijklmno */
 #else
-  99, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, 99, Z_, Z_, Z_, Z_, Z_,	/* @abcdefghijklmno */
+  1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,	/* @abcdefghijklmno */
 #endif
-  Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_,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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,	/* */
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,	/* _!"#$%&'()*+,-./ */
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,	/* 0123456789:;<=>? */
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,	/* */
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,	/* */
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,	/* */
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,	/* */
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,	/* */
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,	/* */
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,	/* */
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,	/* */
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,	/* */
 };
-#undef Z_
 
 /* Functions private to this file. */
 
Index: gas/config/tc-arm.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-arm.c,v
retrieving revision 1.43
diff -u -p -r1.43 tc-arm.c
--- tc-arm.c	2000/05/15 19:25:22	1.43
+++ tc-arm.c	2000/05/31 07:02:37
@@ -2216,7 +2216,7 @@ my_get_float_expression (str)
   memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
   /* Look for a raw floating point number */
   if ((save_in = atof_ieee (*str, 'x', words)) != NULL
-      && (is_end_of_line [(int)(*save_in)] || *save_in == '\0'))
+      && is_end_of_line [(unsigned char) *save_in])
     {
       for (i = 0; i < NUM_FLOAT_VALS; i++)
 	{
@@ -2641,7 +2641,7 @@ fp_op2 (str)
 		  char *start = *str;
 
 		  *str += strlen (fp_const[i]);
-		  if (is_end_of_line[(int)**str] || **str == '\0')
+		  if (is_end_of_line[(unsigned char) **str])
 		    {
 		      inst.instruction |= i + 8;
 		      return SUCCESS;
Index: gas/config/tc-h8500.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-h8500.c,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 tc-h8500.c
--- tc-h8500.c	1999/05/03 07:28:42	1.1.1.1
+++ tc-h8500.c	2000/05/31 07:02:48
@@ -1104,8 +1104,7 @@ DEFUN (md_assemble, (str),
 
   /* find the op code end */
   for (op_start = op_end = str;
-       *op_end &&
-       !is_end_of_line[*op_end] && *op_end != ' ';
+       !is_end_of_line[(unsigned char) *op_end] && *op_end != ' ';
        op_end++)
     {
       if (			/**op_end != '.'
Index: gas/config/tc-m88k.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-m88k.c,v
retrieving revision 1.2
diff -u -p -r1.2 tc-m88k.c
--- tc-m88k.c	1999/06/22 14:52:56	1.2
+++ tc-m88k.c	2000/05/31 07:02:50
@@ -1311,7 +1311,7 @@ s_bss ()
       as_warn (_("Ignoring attempt to re-define symbol %s."), name);
     }
 
-  while (!is_end_of_line[*input_line_pointer])
+  while (!is_end_of_line[(unsigned char) *input_line_pointer])
     {
       input_line_pointer++;
     }
Index: gas/config/tc-mcore.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-mcore.c,v
retrieving revision 1.15
diff -u -p -r1.15 tc-mcore.c
--- tc-mcore.c	2000/05/03 18:50:55	1.15
+++ tc-mcore.c	2000/05/31 07:03:15
@@ -239,7 +239,7 @@ mcore_cons (nbytes)
       int    commas = 1;
       
       /* Count the number of commas on the line.  */
-      while (! is_end_of_line [* ptr])
+      while (! is_end_of_line [(unsigned char) * ptr])
 	commas += * ptr ++ == ',';
       
       poolspan += nbytes * commas;
@@ -268,7 +268,7 @@ mcore_float_cons (float_type)
 #endif
       
       /* Count the number of commas on the line.  */
-      while (! is_end_of_line [* ptr])
+      while (! is_end_of_line [(unsigned char) * ptr])
 	commas += * ptr ++ == ',';
 
       /* We would like to compute "hex_float (float_type) * commas"
@@ -301,7 +301,7 @@ mcore_stringer (append_zero)
 	 estimate, which is OK, and automatically allows for the
 	 appending a zero byte, since the real string(s) is/are
 	 required to be enclosed in double quotes.  */
-      while (! is_end_of_line [* ptr])
+      while (! is_end_of_line [(unsigned char) * ptr])
 	ptr ++;
 
       poolspan += ptr - input_line_pointer;
@@ -975,7 +975,7 @@ md_assemble (str)
 
   /* Find the op code end.  */
   for (op_start = op_end = str;
-       * op_end && nlen < 20 && !is_end_of_line [*op_end] && *op_end != ' ';
+       nlen < 20 && !is_end_of_line [(unsigned char) *op_end] && *op_end != ' ';
        op_end++)
     {
       name[nlen] = op_start[nlen];
Index: gas/config/tc-tic30.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-tic30.c,v
retrieving revision 1.2
diff -u -p -r1.2 tc-tic30.c
--- tc-tic30.c	1999/06/22 14:07:39	1.2
+++ tc-tic30.c	2000/05/31 07:03:24
@@ -1459,7 +1459,7 @@ tic30_find_parallel_insn (current_line, 
   char *parallel_insn;
 
   debug ("In tic30_find_parallel_insn()\n");
-  while (!is_end_of_line[(int) *next_line])
+  while (!is_end_of_line[(unsigned char) *next_line])
     {
       if (*next_line == PARALLEL_SEPARATOR && *(next_line + 1) == PARALLEL_SEPARATOR)
 	{
@@ -1495,7 +1495,7 @@ tic30_find_parallel_insn (current_line, 
 	  int char_ptr = 0;
 	  char c;
 
-	  while (!is_end_of_line[(int) (c = *line)] && *line)
+	  while (!is_end_of_line[(unsigned char) (c = *line)])
 	    {
 	      if (is_opcode_char (c) && search_status == NONE)
 		{
@@ -1682,7 +1682,8 @@ md_atof (what_statement_type, literalP, 
   debug ("literal = %s\n", literalP);
   debug ("line = ");
   token = input_line_pointer;
-  while (!is_end_of_line[(unsigned) *input_line_pointer] && (*input_line_pointer) && (*input_line_pointer != ','))
+  while (!is_end_of_line[(unsigned char) *input_line_pointer]
+	 && (*input_line_pointer != ','))
     {
       debug ("%c", *input_line_pointer);
       input_line_pointer++;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]