public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gas: correct ignoring of C-style number suffixes
@ 2023-10-30 14:38 Jan Beulich
  2023-10-31 10:05 ` Frager, Neal
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Beulich @ 2023-10-30 14:38 UTC (permalink / raw)
  To: Binutils; +Cc: Neal Frager

First of all the respective original changes didn't deal with just 0
having such a suffix - this needs additional logic outside of
integer_constant(). Further bogus suffixes having more than two L-s
were accepted, while valid suffixes with U following the L(s) weren't.
Finally respective tests were introduced for Sparc only.
---
Instead of disabling the test for tic{,5}4x an alternative might be to
use .dc.b. What I'm unclear about is whether that then really results in
rubbish for those two targets (i.e. I'm uncertain whether they really
shouldn't also override those directives).

--- a/gas/expr.c
+++ b/gas/expr.c
@@ -538,17 +538,26 @@ integer_constant (int radix, expressionS
 #ifndef tc_allow_U_suffix
 #define tc_allow_U_suffix 1
 #endif
+  bool u_seen = !tc_allow_U_suffix;
   /* PR 19910: Look for, and ignore, a U suffix to the number.  */
-  if (tc_allow_U_suffix && (c == 'U' || c == 'u'))
-    c = * input_line_pointer++;
+  if (!u_seen && (c == 'U' || c == 'u'))
+    {
+      c = *input_line_pointer++;
+      u_seen = true;
+    }
 
 #ifndef tc_allow_L_suffix
 #define tc_allow_L_suffix 1
 #endif
   /* PR 20732: Look for, and ignore, a L or LL suffix to the number.  */
-  if (tc_allow_L_suffix)
-    while (c == 'L' || c == 'l')
+  if (tc_allow_L_suffix && (c == 'L' || c == 'l'))
+    {
       c = * input_line_pointer++;
+      if (c == 'L' || c == 'l')
+	c = *input_line_pointer++;
+      if (!u_seen && (c == 'U' || c == 'u'))
+	c = *input_line_pointer++;
+    }
 
   if (small)
     {
@@ -888,6 +897,19 @@ operand (expressionS *expressionP, enum
 	    input_line_pointer++;
 	  goto default_case;
 
+	case 'l':
+	case 'L':
+	  /* Accept an L suffix to the zero.  */
+	  if (tc_allow_L_suffix)
+	    goto numeric;
+	  goto default_case;
+
+	case 'u':
+	case 'U':
+	  /* Accept a U suffix to the zero.  */
+	  if (!tc_allow_U_suffix)
+	    goto default_case;
+	  /* Fall through.  */
 	case '0':
 	case '1':
 	case '2':
@@ -896,6 +918,7 @@ operand (expressionS *expressionP, enum
 	case '5':
 	case '6':
 	case '7':
+	numeric:
 	  integer_constant ((flag_m68k_mri || NUMBERS_WITH_SUFFIX)
 			    ? 0 : 8,
 			    expressionP);
--- /dev/null
+++ b/gas/testsuite/gas/all/const-1.l
@@ -0,0 +1,64 @@
+# This should match the output of gas -alm const-1.s.
+.*: Assembler messages:
+.*:5: Error: .*`l'
+.*:18:  Info: .*
+.*:6: Error: .*`l'
+.*:18:  Info: .*
+.*:7: Error: .*`l'
+.*:18:  Info: .*
+.*:8: Error: .*`l'
+.*:18:  Info: .*
+.*:5: Error: .*`u'
+.*:19:  Info: .*
+.*:6: Error: .*`u'
+.*:19:  Info: .*
+.*:7: Error: .*`u'
+.*:19:  Info: .*
+.*:8: Error: .*`u'
+.*:19:  Info: .*
+.*:5: Error: .*`l'
+.*:20:  Info: .*
+.*:6: Error: .*`l'
+.*:20:  Info: .*
+.*:7: Error: .*`l'
+.*:20:  Info: .*
+.*:8: Error: .*`l'
+.*:20:  Info: .*
+.*GAS .*/const-1\.s[ 	].*
+#...
+[ 	]*[0-9]*[ 	]+const u
+[ 	]*[0-9]*[ 	]+\?\?\?\? 00[ 	]+>  \.byte 0u
+[ 	]*[0-9]*[ 	]+\?\?\?\? 00[ 	]+>  \.byte 00u
+[ 	]*[0-9]*[ 	]+\?\?\?\? 00[ 	]+>  \.byte 0x0u
+[ 	]*[0-9]*[ 	]+\?\?\?\? 01[ 	]+>  \.byte 1u
+[ 	]*[0-9]*[ 	]+const l
+[ 	]*[0-9]*[ 	]+\?\?\?\? 00[ 	]+>  \.byte 0l
+[ 	]*[0-9]*[ 	]+\?\?\?\? 00[ 	]+>  \.byte 00l
+[ 	]*[0-9]*[ 	]+\?\?\?\? 00[ 	]+>  \.byte 0x0l
+[ 	]*[0-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.byte 0x0ull
+[ 	]*[0-9]*[ 	]+\?\?\?\? 01[ 	]+>  \.byte 1ull
+#pass
--- /dev/null
+++ b/gas/testsuite/gas/all/const-1.s
@@ -0,0 +1,20 @@
+	.data
+data:
+
+	.macro const, sfx
+	.byte 0\sfx
+	.byte 00\sfx
+	.byte 0x0\sfx
+	.byte 1\sfx
+	.endm
+
+	const u
+	const l
+	const ul
+	const lu
+	const ll
+	const llu
+	const ull
+	const lll
+	const ulu
+	const lul
--- a/gas/testsuite/gas/all/gas.exp
+++ b/gas/testsuite/gas/all/gas.exp
@@ -469,6 +469,11 @@ run_list_test cond-2 "-al"
 setup_xfail "tic30-*-*"
 run_list_test linefile ""
 
+# Again, .byte does not emit 8 bits on either tic4x or tic54x.
+if { ![istarget "tic4x*-*-*"] && ![istarget "tic54x*-*-*"] } {
+    run_list_test const-1 "-alm"
+}
+
 run_list_test macro "-alm"
 
 run_list_test pr20312

^ permalink raw reply	[flat|nested] 2+ messages in thread

* RE: [PATCH] gas: correct ignoring of C-style number suffixes
  2023-10-30 14:38 [PATCH] gas: correct ignoring of C-style number suffixes Jan Beulich
@ 2023-10-31 10:05 ` Frager, Neal
  0 siblings, 0 replies; 2+ messages in thread
From: Frager, Neal @ 2023-10-31 10:05 UTC (permalink / raw)
  To: Jan Beulich, Binutils

> First of all the respective original changes didn't deal with just 0 having such a suffix - this needs additional logic outside of integer_constant(). Further bogus suffixes having more than two L-s were accepted, while valid suffixes with U following the L(s) weren't.
> Finally respective tests were introduced for Sparc only.
> ---
> Instead of disabling the test for tic{,5}4x an alternative might be to use .dc.b. What I'm unclear about is whether that then really results in rubbish for those two targets (i.e. I'm uncertain whether they really shouldn't also override those directives).

Reviewed-by: Neal Frager <neal.frager@amd.com>

Thank you for developing this solution.

Best regards,
Neal Frager
AMD

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-10-31 10:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-30 14:38 [PATCH] gas: correct ignoring of C-style number suffixes Jan Beulich
2023-10-31 10:05 ` Frager, Neal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).