]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gas: correctly deal with line comments when not preprocessing
authorJan Beulich <jbeulich@suse.com>
Fri, 2 Aug 2024 07:43:58 +0000 (09:43 +0200)
committerJan Beulich <jbeulich@suse.com>
Fri, 2 Aug 2024 07:43:58 +0000 (09:43 +0200)
Internal naming of functions / data as well as commentary mixes lines
and statements. It is presumably this confusion which has led to the
wrong use of ignore_rest_of_line() when dealing with line comments in
read_a_source_file(). We shall not (silently) produce different output
depending on whether -f is passed (for suitable input).

Introduce two new helper macros, intended to be used in favor of open-
coded accesses to is_end_of_line[]. To emphasize the difference, convert
ignore_rest_of_line() right away, including adjustments to its comments.

Since most targets have # in line_comment_chars[], add a target-
independent test for that, plus an x86-only one also checking for non-#
to work as intended.

gas/read.c
gas/read.h
gas/testsuite/gas/all/gas.exp
gas/testsuite/gas/all/line-comment.d [new file with mode: 0644]
gas/testsuite/gas/all/line-comment.s [new file with mode: 0644]
gas/testsuite/gas/i386/i386.exp
gas/testsuite/gas/i386/line-comment.d [new file with mode: 0644]
gas/testsuite/gas/i386/line-comment.s [new file with mode: 0644]

index 9a26a9a5b7a5a7329a6159631d7fafa88995773d..adb4759a96bfd2f545cd86bc91903f1845c72e76 100644 (file)
@@ -1324,8 +1324,11 @@ read_a_source_file (const char *name)
              s = input_line_pointer;
              if (!startswith (s, "APP\n"))
                {
-                 /* We ignore it.  */
-                 ignore_rest_of_line ();
+                 /* We ignore it.  Note: Not ignore_rest_of_line ()!  */
+                 while (s <= buffer_limit)
+                   if (is_end_of_line (*s++))
+                     break;
+                 input_line_pointer = s;
                  continue;
                }
              bump_line_counters ();
@@ -3974,7 +3977,7 @@ demand_empty_rest_of_line (void)
   /* Return pointing just after end-of-line.  */
 }
 
-/* Silently advance to the end of line.  Use this after already having
+/* Silently advance to the end of a statement.  Use this after already having
    issued an error about something bad.  Like demand_empty_rest_of_line,
    this function may leave input_line_pointer one after buffer_limit;
    Don't call it from within expression parsing code in an attempt to
@@ -3984,9 +3987,9 @@ void
 ignore_rest_of_line (void)
 {
   while (input_line_pointer <= buffer_limit)
-    if (is_end_of_line[(unsigned char) *input_line_pointer++])
+    if (is_end_of_stmt (*input_line_pointer++))
       break;
-  /* Return pointing just after end-of-line.  */
+  /* Return pointing just after end-of-statement.  */
 }
 
 /* Sets frag for given symbol to zero_address_frag, except when the
index 2441d560bbd8a2836d9a20da281bb08b3fd974cb..3cdd408168fd93acc1e84bb474f6840b0be655df 100644 (file)
@@ -58,6 +58,14 @@ extern bool input_from_string;
 #define is_name_ender(c) \
   ( lex_type[(unsigned char) (c)] & LEX_END_NAME   )
 
+/* The distinction of "line" and "statement" sadly is blurred by unhelpful
+   naming of e.g. the underlying array.  Most users really mean "end of
+   statement".  Going forward only these wrappers are supposed to be used.  */
+#define is_end_of_stmt(c) \
+  (is_end_of_line[(unsigned char) (c)])
+#define is_end_of_line(c) \
+  (is_end_of_line[(unsigned char) (c)] == 1)
+
 #ifndef is_a_char
 #define CHAR_MASK      (0xff)
 #define NOT_A_CHAR     (CHAR_MASK+1)
index 24376a728d86d0fc2fa2b782e452f4897c017249..d42d8df3cebcf6aa5eae9f8d8db0d4714f09cc71 100644 (file)
@@ -490,6 +490,10 @@ if { ![istarget "tic4x*-*-*"] && ![istarget "tic54x*-*-*"] } {
     run_list_test const-1 "-alm"
 }
 
+if { ![istarget "tic30-*-*"] } {
+    run_dump_test "line-comment"
+}
+
 run_list_test macro "-alm"
 
 run_list_test pr20312
diff --git a/gas/testsuite/gas/all/line-comment.d b/gas/testsuite/gas/all/line-comment.d
new file mode 100644 (file)
index 0000000..9531ba8
--- /dev/null
@@ -0,0 +1,12 @@
+#as:
+#as: -f
+#objdump: -dw --disassemble-zeroes
+#name: generic line comment
+
+.*: +file format .*
+
+Disassembly of section .text:
+
+0+ <(line_comment|\.text)>:
+ +0+:  .*
+#pass
diff --git a/gas/testsuite/gas/all/line-comment.s b/gas/testsuite/gas/all/line-comment.s
new file mode 100644 (file)
index 0000000..6f74bde
--- /dev/null
@@ -0,0 +1,4 @@
+       .text
+line_comment:
+       #.warning;$@!|.error
+       .nop
index 590a55d0c81142faa82ce38f841b3e7cc7c5742f..3e707b3d0c6272697e2a33bf8a4eeac68872b707 100644 (file)
@@ -106,6 +106,7 @@ if [gas_32_check] then {
     run_list_test "equ-2" "-al"
     run_list_test "equ-bad"
     run_list_test "comments" "-almn"
+    run_dump_test "line-comment"
     run_dump_test "curly"
     run_dump_test "separator"
     run_dump_test "divide"
diff --git a/gas/testsuite/gas/i386/line-comment.d b/gas/testsuite/gas/i386/line-comment.d
new file mode 100644 (file)
index 0000000..4d989a4
--- /dev/null
@@ -0,0 +1,13 @@
+#as:
+#as: -f
+#objdump: -dw
+#name: i386 line comment
+
+.*: +file format .*
+
+Disassembly of section .text:
+
+0+ <line_comment>:
+ +[a-f0-9]+:   90[     ]+nop
+ +[a-f0-9]+:   c3[     ]+ret
+#pass
diff --git a/gas/testsuite/gas/i386/line-comment.s b/gas/testsuite/gas/i386/line-comment.s
new file mode 100644 (file)
index 0000000..e0d6e9a
--- /dev/null
@@ -0,0 +1,6 @@
+       .text
+line_comment:
+       nop
+       #aaa;aas
+       /aad;aam
+       ret