This is the mail archive of the binutils@sources.redhat.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]
Other format: [Raw text]

Re: sh assembler mis-assembles @(r0) and @(r0,)


On Dec 18, 2001, Hans-Peter Nilsson <hp@bitrange.com> wrote:

> On 18 Dec 2001, Nick Clifton wrote:
>> > Index: gas/ChangeLog
>> > from  Alexandre Oliva  <aoliva@redhat.com>
>> >
>> > 	* config/tc-sh.c (parse_at): Reject @(r0) and @(r0,).
>> 
>> Approved - please apply.

> Oops, sorry, I should have looked at this.  Alex, could you also
> please add dg test-cases for this to the gas test-suite?  See
> sh/err-*.s; a new file is all that's needed.

Thanks for the pointer.  Here's the patch, with testcase, I'm about to
check in.

Index: gas/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* config/tc-sh.c (parse_at): Reject @(r0) and @(r0,).

Index: gas/config/tc-sh.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-sh.c,v
retrieving revision 1.49
diff -u -p -r1.49 tc-sh.c
--- gas/config/tc-sh.c 2001/12/05 09:52:32 1.49
+++ gas/config/tc-sh.c 2001/12/20 17:26:06
@@ -914,7 +914,7 @@ parse_at (src, op)
   else if (src[0] == '(')
     {
       /* Could be @(disp, rn), @(disp, gbr), @(disp, pc),  @(r0, gbr) or
-         @(r0, rn) */
+         @(r0, rn).  */
       src++;
       len = parse_reg (src, &mode, &(op->reg));
       if (len && mode == A_REG_N)
@@ -925,29 +925,42 @@ parse_at (src, op)
 	      as_bad (_("must be @(r0,...)"));
 	    }
 	  if (src[0] == ',')
-	    src++;
-	  /* Now can be rn or gbr */
-	  len = parse_reg (src, &mode, &(op->reg));
-	  if (mode == A_GBR)
+	    {
+	      src++;
+	      /* Now can be rn or gbr.  */
+	      len = parse_reg (src, &mode, &(op->reg));
+	    }
+	  else
 	    {
-	      op->type = A_R0_GBR;
+	      len = 0;
 	    }
-	  else if (mode == A_REG_N)
+	  if (len)
 	    {
-	      op->type = A_IND_R0_REG_N;
+	      if (mode == A_GBR)
+		{
+		  op->type = A_R0_GBR;
+		}
+	      else if (mode == A_REG_N)
+		{
+		  op->type = A_IND_R0_REG_N;
+		}
+	      else
+		{
+		  as_bad (_("syntax error in @(r0,...)"));
+		}
 	    }
 	  else
 	    {
-	      as_bad (_("syntax error in @(r0,...)"));
+	      as_bad (_("syntax error in @(r0...)"));
 	    }
 	}
       else
 	{
-	  /* Must be an @(disp,.. thing) */
+	  /* Must be an @(disp,.. thing).  */
 	  src = parse_exp (src, op);
 	  if (src[0] == ',')
 	    src++;
-	  /* Now can be rn, gbr or pc */
+	  /* Now can be rn, gbr or pc.  */
 	  len = parse_reg (src, &mode, &op->reg);
 	  if (len)
 	    {
Index: gas/testsuite/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* gas/sh/err-at.s: New test.

Index: gas/testsuite/gas/sh/err-at.s
===================================================================
RCS file: err-at.s
diff -N err-at.s
--- /dev/null	Tue May  5 13:32:27 1998
+++ gas/testsuite/gas/sh/err-at.s Thu Dec 20 09:26:06 2001
@@ -0,0 +1,10 @@
+! { dg-do assemble }
+
+! Make sure we reject the invalid uses below:
+start:
+	mov.l	r1,@r0		! ok
+	mov.l	r1,@(r0)	! { dg-error "syntax error" }
+	mov.l	r1,@(r0,)	! { dg-error "syntax error" }
+	mov.l	r1,@(r0,r0)	! ok
+	mov.l	r1,@(r0,r1)	! ok
+	mov.l	r1,@(r1,r0)	! { dg-error "must be" }

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me

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