[02/11] gas: drop scrubber state -2

Message ID 9ade1ea8-3ea5-4015-8efe-192406d30c6b@suse.com
State Superseded
Headers
Series gas: scrubber adjustments |

Commit Message

Jan Beulich June 28, 2024, 1:17 p.m. UTC
  Instead re-use code handling LEX_IS_TWOCHAR_COMMENT_1ST, thus ensuring
that we wouldn't get bogus state transitions: For example, when we're
in states 0 or 1, a comment should be no different from whitespace
encountered in those states. Plus for e.g. x86 this results in such
comments now truly being converted to a blank, as mandated by
documentation. Both aspects apparently were a result of blindly (and
wrongly) moving to state 3 _before_ consuming the "ungot" blank.

Also amend a related comment elsewhere.

In the new testcase the .irp is to make visible in the listing all the
whitespace that the scrubber inserts / leaves in place.
  

Patch

--- a/gas/app.c
+++ b/gas/app.c
@@ -172,7 +172,8 @@  do_scrub_begin (int m68k_mri ATTRIBUTE_U
     lex[(unsigned char) *p] = LEX_IS_PARALLEL_SEPARATOR;
 #endif
 
-  /* Only allow slash-star comments if slash is not in use.
+  /* Only allow slash-star comments if slash is not in use.  Certain
+     other cases are dealt with in LEX_IS_LINE_COMMENT_START handling.
      FIXME: This isn't right.  We should always permit them.  */
   if (lex['/'] == 0)
     lex['/'] = LEX_IS_TWOCHAR_COMMENT_1ST;
@@ -435,7 +436,6 @@  do_scrub_chars (size_t (*get) (char *, s
 	 10: After seeing whitespace in state 9 (keep white before symchar)
 	 11: After seeing a symbol character in state 0 (eg a label definition)
 	 -1: output string in out_string and go to the state in old_state
-	 -2: flush text until a '*' '/' is seen, then go to state old_state
 	 12: no longer used
 #ifdef DOUBLEBAR_PARALLEL
 	 13: After seeing a vertical bar, looking for a second
@@ -538,43 +538,6 @@  do_scrub_chars (size_t (*get) (char *, s
 	  PUT (ch);
 	  continue;
 
-	case -2:
-	  for (;;)
-	    {
-	      do
-		{
-		  ch = GET ();
-
-		  if (ch == EOF)
-		    {
-		      as_warn (_("end of file in comment"));
-		      goto fromeof;
-		    }
-
-		  if (ch == '\n')
-		    PUT ('\n');
-		}
-	      while (ch != '*');
-
-	      while ((ch = GET ()) == '*')
-		;
-
-	      if (ch == EOF)
-		{
-		  as_warn (_("end of file in comment"));
-		  goto fromeof;
-		}
-
-	      if (ch == '/')
-		break;
-
-	      UNGET (ch);
-	    }
-
-	  state = old_state;
-	  UNGET (' ');
-	  continue;
-
 	case 4:
 	  ch = GET ();
 	  if (ch == EOF)
@@ -1031,6 +994,7 @@  do_scrub_chars (size_t (*get) (char *, s
 	  ch2 = GET ();
 	  if (ch2 == '*')
 	    {
+	twochar_comment:
 	      for (;;)
 		{
 		  do
@@ -1245,15 +1209,9 @@  do_scrub_chars (size_t (*get) (char *, s
 	    {
 	      ch2 = GET ();
 	      if (ch2 == '*')
-		{
-		  old_state = 3;
-		  state = -2;
-		  break;
-		}
-	      else if (ch2 != EOF)
-		{
-		  UNGET (ch2);
-		}
+		goto twochar_comment;
+	      if (ch2 != EOF)
+		UNGET (ch2);
 	    }
 
 	  if (state == 0 || state == 1)	/* Only comment at start of line.  */
--- /dev/null
+++ b/gas/testsuite/gas/i386/comments.l
@@ -0,0 +1,30 @@ 
+.*: Assembler messages:
+.*:6: Error: .*
+.*:7: Error: .*
+[ 	]*[0-9]+[ 	]+scrubber:
+[ 	]*[0-9]+[ 	]+\.irp x,""
+[ 	]*[0-9]+[ 	]*
+[ 	]*[0-9]+[ 	]+/\*    \*/vaddps	%zmm0, %zmm1, %zmm2
+[ 	]*[0-9]+[ 	]+vaddps/\*\*/%zmm0, %zmm1, %zmm2
+[ 	]*[0-9]+[ 	]+vadd/\*\*/ps %zmm0, %zmm1, %zmm2
+[ 	]*[0-9]+[ 	]+vaddps	%zmm/\*\*/0, %zmm1, %zmm2
+[ 	]*[0-9]+[ 	]*
+[ 	]*[0-9]+[ 	]+vaddps	%zmm0, %zmm1, %zmm2# ...
+[ 	]*[0-9]+[ 	]+vaddps	%zmm0, %zmm1, %zmm2	# ...
+[ 	]*[0-9]+[ 	]+vaddps	%zmm0, %zmm1, %zmm2/\*    \*/# ...
+[ 	]*[0-9]+[ 	]*
+[ 	]*[0-9]+[ 	]+\.endr
+[ 	]*[0-9]+[ 	]+> +
+[ 	]*[0-9]+ \?\?\?\? [0-9A-F]+[ 	]+>  vaddps %zmm0,%zmm1,%zmm2
+#...
+[ 	]*[0-9]+ \?\?\?\? [0-9A-F]+[ 	]+>  vaddps %zmm0,%zmm1,%zmm2
+#...
+[ 	]*[0-9]+[ 	]+>  vadd ps %zmm0,%zmm1,%zmm2
+[ 	]*[0-9]+[ 	]+>  vaddps %zmm 0,%zmm1,%zmm2
+[ 	]*[0-9]+[ 	]+> +
+[ 	]*[0-9]+ \?\?\?\? [0-9A-F]+[ 	]+>  vaddps %zmm0,%zmm1,%zmm2
+#...
+[ 	]*[0-9]+ \?\?\?\? [0-9A-F]+[ 	]+>  vaddps %zmm0,%zmm1,%zmm2
+#...
+[ 	]*[0-9]+ \?\?\?\? [0-9A-F]+[ 	]+>  vaddps %zmm0,%zmm1,%zmm2
+#pass
--- /dev/null
+++ b/gas/testsuite/gas/i386/comments.s
@@ -0,0 +1,13 @@ 
+scrubber:
+	.irp x,""
+
+/*    */vaddps	%zmm0, %zmm1, %zmm2
+	vaddps/**/%zmm0, %zmm1, %zmm2
+	vadd/**/ps %zmm0, %zmm1, %zmm2
+	vaddps	%zmm/**/0, %zmm1, %zmm2
+
+	vaddps	%zmm0, %zmm1, %zmm2# ...
+	vaddps	%zmm0, %zmm1, %zmm2	# ...
+	vaddps	%zmm0, %zmm1, %zmm2/*    */# ...
+
+	.endr
--- a/gas/testsuite/gas/i386/i386.exp
+++ b/gas/testsuite/gas/i386/i386.exp
@@ -105,6 +105,7 @@  if [gas_32_check] then {
     run_dump_test "equ"
     run_list_test "equ-2" "-al"
     run_list_test "equ-bad"
+    run_list_test "comments" "-almn"
     run_dump_test "divide"
     run_dump_test "quoted"
     run_dump_test "quoted2"