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]

Re: Problem with .elseif conditional in binutils-2.10 gas


On Sat, 31 Mar 2001, Alan Modra wrote:

> On Fri, 30 Mar 2001, Michael Schwingen wrote:
> 
> > I am having problems with the .elseif conditional in as of binutils 2.10
> 
> Fixed, along with a potential abort on invalid input.  Thanks for the
> report.

Except that conditional assembly listing (-alc) was still broken for
anything with more than one .else/.elseif branch.

gas/ChangeLog
	* listing.c (listing_listing): Enable listing on EDICT_NOLIST_NEXT
	for one line if not already enabled.
	* cond.c (s_elseif): Correct conditional assembly listing.
	(s_else): Likewise.

gas/testsuite/ChangeLog
	* gas/all/cond.s: Add .if .elseif tree.
	* gas/all/cond.d: Match above.

Alan Modra
-- 
Linuxcare

Index: cond.c
===================================================================
RCS file: /cvs/src/src/gas/cond.c,v
retrieving revision 1.9
diff -u -p -r1.9 cond.c
--- cond.c	2001/03/31 02:06:24	1.9
+++ cond.c	2001/03/31 05:54:05
@@ -255,9 +255,6 @@ void
 s_elseif (arg)
      int arg;
 {
-  expressionS operand;
-  int t;
-
   if (current_cframe == NULL)
     {
       as_bad (_("\".elseif\" without matching \".if\" - ignored"));
@@ -277,54 +274,55 @@ s_elseif (arg)
       as_where (&current_cframe->else_file_line.file,
 		&current_cframe->else_file_line.line);
 
-      if (!current_cframe->dead_tree)
-	{
-	  current_cframe->dead_tree = !current_cframe->ignoring;
-	  current_cframe->ignoring = !current_cframe->ignoring;
-	  if (LISTING_SKIP_COND ())
-	    {
-	      if (! current_cframe->ignoring)
-		listing_list (1);
-	      else
-		listing_list (2);
-	    }
-	}			/* if not a dead tree */
-    }				/* if error else do it */
+      current_cframe->dead_tree |= !current_cframe->ignoring;
+      current_cframe->ignoring = current_cframe->dead_tree;
+    }
 
   if (current_cframe == NULL || current_cframe->ignoring)
     {
       while (! is_end_of_line[(unsigned char) *input_line_pointer])
 	++input_line_pointer;
-      return;
+
+      if (current_cframe == NULL)
+	return;
     }
+  else
+    {
+      expressionS operand;
+      int t;
 
-  /* Leading whitespace is part of operand.  */
-  SKIP_WHITESPACE ();
+      /* Leading whitespace is part of operand.  */
+      SKIP_WHITESPACE ();
 
-  expression (&operand);
-  if (operand.X_op != O_constant)
-    as_bad (_("non-constant expression in \".elseif\" statement"));
+      expression (&operand);
+      if (operand.X_op != O_constant)
+	as_bad (_("non-constant expression in \".elseif\" statement"));
 
-  switch ((operatorT) arg)
-    {
-    case O_eq: t = operand.X_add_number == 0; break;
-    case O_ne: t = operand.X_add_number != 0; break;
-    case O_lt: t = operand.X_add_number < 0; break;
-    case O_le: t = operand.X_add_number <= 0; break;
-    case O_ge: t = operand.X_add_number >= 0; break;
-    case O_gt: t = operand.X_add_number > 0; break;
-    default:
-      abort ();
-      return;
-    }
+      switch ((operatorT) arg)
+	{
+	case O_eq: t = operand.X_add_number == 0; break;
+	case O_ne: t = operand.X_add_number != 0; break;
+	case O_lt: t = operand.X_add_number < 0; break;
+	case O_le: t = operand.X_add_number <= 0; break;
+	case O_ge: t = operand.X_add_number >= 0; break;
+	case O_gt: t = operand.X_add_number > 0; break;
+	default:
+	  abort ();
+	  return;
+	}
 
-  current_cframe->ignoring = current_cframe->dead_tree || ! t;
+      current_cframe->ignoring = current_cframe->dead_tree || ! t;
+    }
 
   if (LISTING_SKIP_COND ()
-      && current_cframe->ignoring
       && (current_cframe->previous_cframe == NULL
 	  || ! current_cframe->previous_cframe->ignoring))
-    listing_list (2);
+    {
+      if (! current_cframe->ignoring)
+	listing_list (1);
+      else
+	listing_list (2);
+    }
 
   demand_empty_rest_of_line ();
 }
@@ -368,7 +366,6 @@ s_else (arg)
   if (current_cframe == NULL)
     {
       as_bad (_(".else without matching .if - ignored"));
-
     }
   else if (current_cframe->else_seen)
     {
@@ -384,21 +381,22 @@ s_else (arg)
     {
       as_where (&current_cframe->else_file_line.file,
 		&current_cframe->else_file_line.line);
+
+      current_cframe->ignoring =
+	current_cframe->dead_tree | !current_cframe->ignoring;
 
-      if (!current_cframe->dead_tree)
+      if (LISTING_SKIP_COND ()
+	  && (current_cframe->previous_cframe == NULL
+	      || ! current_cframe->previous_cframe->ignoring))
 	{
-	  current_cframe->ignoring = !current_cframe->ignoring;
-	  if (LISTING_SKIP_COND ())
-	    {
-	      if (! current_cframe->ignoring)
-		listing_list (1);
-	      else
-		listing_list (2);
-	    }
-	}			/* if not a dead tree */
+	  if (! current_cframe->ignoring)
+	    listing_list (1);
+	  else
+	    listing_list (2);
+	}
 
       current_cframe->else_seen = 1;
-    }				/* if error else do it */
+    }
 
   if (flag_mri)
     {
Index: listing.c
===================================================================
RCS file: /cvs/src/src/gas/listing.c,v
retrieving revision 1.13
diff -u -p -r1.13 listing.c
--- listing.c	2001/03/08 23:24:22	1.13
+++ listing.c	2001/03/31 06:19:25
@@ -1007,6 +1007,8 @@ listing_listing (name)
 	  show_listing--;
 	  break;
 	case EDICT_NOLIST_NEXT:
+	  if (show_listing == 0)
+	    list_line--;
 	  break;
 	case EDICT_EJECT:
 	  break;
@@ -1029,7 +1031,8 @@ listing_listing (name)
 	    p = buffer_line (list->file, buffer, width);
 	}
 
-      if (list->edict == EDICT_LIST)
+      if (list->edict == EDICT_LIST
+	  || (list->edict == EDICT_NOLIST_NEXT && show_listing == 0))
 	{
 	  /* Enable listing for the single line that caused the enable.  */
 	  list_line++;
@@ -1090,7 +1093,7 @@ listing_listing (name)
 	    }
 	}
 
-      if (list->edict == EDICT_NOLIST_NEXT)
+      if (list->edict == EDICT_NOLIST_NEXT && show_listing == 1)
 	--show_listing;
 
       list = list->next;
Index: testsuite/gas/all/cond.s
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/all/cond.s,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 cond.s
--- cond.s	1999/05/03 07:28:47	1.1.1.1
+++ cond.s	2001/03/31 05:54:22
@@ -15,4 +15,18 @@
 	.long	4
 	.endc
 	.endc
+
+	.if	0
+	.long	5
+	.elseif	1
+	.if	0
+	.long	6
+	.elseif	1
+	.long	7
+	.endif
+	.elseif	1
+	.long	8
+	.else
+	.long	9
+	.endif
 	.p2align 5,0
Index: testsuite/gas/all/cond.d
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/all/cond.d,v
retrieving revision 1.2
diff -u -p -r1.2 cond.d
--- cond.d	2000/03/27 23:47:09	1.2
+++ cond.d	2001/03/31 05:54:22
@@ -13,8 +13,18 @@
   15 0004 0[04] ?00 ?00 ?0[04][ 	]+.long[ 	]+4
   16[ 	]+.endc
   17[ 	]+.endc
-  18 0008 00 ?00 ?00 ?00[ 	]+.p2align 5,0
-  18[ 	]+00 ?00 ?00 ?00 
-  18[ 	]+00 ?00 ?00 ?00 
-  18[ 	]+00 ?00 ?00 ?00 
-  18[ 	]+00 ?00 ?00 ?00 
+  18[ 	]+
+  19[ 	]+.if	0
+  21[ 	]+.elseif	1
+  22[ 	]+.if	0
+  24[ 	]+.elseif	1
+  25 0008 0[07] ?00 ?00 ?0[07][ 	]+.long[ 	]+7
+  26[ 	]+.endif
+  27[ 	]+.elseif	1
+  29[ 	]+.else
+  31[ 	]+.endif
+  32 000c 00 ?00 ?00 ?00[ 	]+.p2align 5,0
+  32[ 	]+00 ?00 ?00 ?00 
+  32[ 	]+00 ?00 ?00 ?00 
+  32[ 	]+00 ?00 ?00 ?00 
+  32[ 	]+00 ?00 ?00 ?00 



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