[v2,1/1] RISC-V: Fix build with GCC-8

Message ID 20260623124758.2412307-2-zhuangqiubin@linux.spacemit.com
State New
Headers
Series RISC-V: Fix build with GCC-8 |

Commit Message

Mark Zhuang June 23, 2026, 12:47 p.m. UTC
  From: Mark Zhuang <mark.zhuang@spacemit.com>

GCC 8.5.0 rejects a declaration right after a case label.
Add braces to fix it.
---
 gas/config/tc-riscv.c | 54 +++++++++++++++++++++++--------------------
 opcodes/riscv-dis.c   | 16 ++++++++-----
 2 files changed, 39 insertions(+), 31 deletions(-)
  

Comments

Jan Beulich June 23, 2026, 12:53 p.m. UTC | #1
On 23.06.2026 14:47, Mark Zhuang wrote:
> From: Mark Zhuang <mark.zhuang@spacemit.com>
> 
> GCC 8.5.0 rejects a declaration right after a case label.
> Add braces to fix it.
> ---
>  gas/config/tc-riscv.c | 54 +++++++++++++++++++++++--------------------
>  opcodes/riscv-dis.c   | 16 ++++++++-----
>  2 files changed, 39 insertions(+), 31 deletions(-)

Thanks for making the adjustments. I'll give RISC-V maintainers until the
end of the week to approve this. Otherwise I'll take care of it. In that
case, however, I'd likely ...

> @@ -1815,13 +1813,17 @@ validate_riscv_insn (const struct riscv_opcode *opc, int length)
>  		  break;
>  		case 'u': /* Integer immediate, 'XpuN@S' ...
>  			     N-bit unsigned immediate at bit S.  */
> -		  n = strtol (oparg + 1, (char **)&oparg, 10);
> -		  if (*oparg != '@')
> -		    goto unknown_validate_operand;
> -		  s = strtol (oparg + 1, (char **)&oparg, 10);
> -		  oparg--;
> -		  USE_IMM (n, s);
> -		  break;
> +		  {
> +		    size_t n;
> +		    size_t s;
> +		    n = strtol (oparg + 1, (char **)&oparg, 10);

... make this the initializer of n and ...

> +		    if (*oparg != '@')
> +		      goto unknown_validate_operand;
> +		    s = strtol (oparg + 1, (char **)&oparg, 10);

... declare s only here (with initializer).

> +		    oparg--;
> +		    USE_IMM (n, s);
> +		    break;
> +		  }
>  		case 'n':
>  		case 'b':
>  		  used_bits |= ENCODE_SPACEMIT_IME_UIMM2_SP (-1U);
> @@ -4309,8 +4311,6 @@ riscv_ip (char *str, struct riscv_cl_insn *ip, expressionS *imm_expr,
>  		  break;
>  
>  		case 'p': /* Vendor-specific (SpacemiT) operands.  */
> -		  size_t n;
> -		  size_t s;
>  		  switch (*++oparg)
>  		    {
>  		    case 'V':
> @@ -4358,20 +4358,24 @@ riscv_ip (char *str, struct riscv_cl_insn *ip, expressionS *imm_expr,
>  		      break;
>  		    case 'u': /* Integer immediate, 'XpuN@S' ...
>  				 N-bit unsigned immediate at bit S.  */
> -		      n = strtol (oparg + 1, (char **)&oparg, 10);
> -		      if (*oparg != '@')
> -			goto unknown_riscv_ip_operand;
> -		      s = strtol (oparg + 1, (char **)&oparg, 10);
> -		      oparg--;
> -		      my_getExpression (imm_expr, asarg, force_reloc);
> -		      check_absolute_expr (ip, imm_expr, false);
> -		      if (!VALIDATE_U_IMM (imm_expr->X_add_number, n))
> -			as_bad (_("improper immediate value (%"PRIu64")"),
> -				imm_expr->X_add_number);
> -		      INSERT_IMM (n, s, *ip, imm_expr->X_add_number);
> -		      imm_expr->X_op = O_absent;
> -		      asarg = expr_parse_end;
> -		      continue;
> +		      {
> +			size_t n;
> +			size_t s;
> +			n = strtol (oparg + 1, (char **)&oparg, 10);
> +			if (*oparg != '@')
> +			  goto unknown_riscv_ip_operand;
> +			s = strtol (oparg + 1, (char **)&oparg, 10);

Again same here then. In both cases of course only if you don't
vehemently object.

Jan
  
Jan Beulich June 23, 2026, 12:55 p.m. UTC | #2
On 23.06.2026 14:53, Jan Beulich wrote:
> On 23.06.2026 14:47, Mark Zhuang wrote:
>> From: Mark Zhuang <mark.zhuang@spacemit.com>
>>
>> GCC 8.5.0 rejects a declaration right after a case label.
>> Add braces to fix it.
>> ---
>>  gas/config/tc-riscv.c | 54 +++++++++++++++++++++++--------------------
>>  opcodes/riscv-dis.c   | 16 ++++++++-----
>>  2 files changed, 39 insertions(+), 31 deletions(-)
> 
> Thanks for making the adjustments. I'll give RISC-V maintainers until the
> end of the week to approve this.

Noticing only now: To catch their attention, it helps greatly if you actually
Cc them on patch submissions. I've added the missing Cc-s here.

Jan
  

Patch

diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c
index 5ffa2ef1f1d..cb639b48fe0 100644
--- a/gas/config/tc-riscv.c
+++ b/gas/config/tc-riscv.c
@@ -1791,8 +1791,6 @@  validate_riscv_insn (const struct riscv_opcode *opc, int length)
 		}
 		break;
 	    case 'p': /* Vendor-specific (SpacemiT) operands.  */
-	      size_t n;
-	      size_t s;
 	      switch (*++oparg)
 		{
 		case 'V':
@@ -1815,13 +1813,17 @@  validate_riscv_insn (const struct riscv_opcode *opc, int length)
 		  break;
 		case 'u': /* Integer immediate, 'XpuN@S' ...
 			     N-bit unsigned immediate at bit S.  */
-		  n = strtol (oparg + 1, (char **)&oparg, 10);
-		  if (*oparg != '@')
-		    goto unknown_validate_operand;
-		  s = strtol (oparg + 1, (char **)&oparg, 10);
-		  oparg--;
-		  USE_IMM (n, s);
-		  break;
+		  {
+		    size_t n;
+		    size_t s;
+		    n = strtol (oparg + 1, (char **)&oparg, 10);
+		    if (*oparg != '@')
+		      goto unknown_validate_operand;
+		    s = strtol (oparg + 1, (char **)&oparg, 10);
+		    oparg--;
+		    USE_IMM (n, s);
+		    break;
+		  }
 		case 'n':
 		case 'b':
 		  used_bits |= ENCODE_SPACEMIT_IME_UIMM2_SP (-1U);
@@ -4309,8 +4311,6 @@  riscv_ip (char *str, struct riscv_cl_insn *ip, expressionS *imm_expr,
 		  break;
 
 		case 'p': /* Vendor-specific (SpacemiT) operands.  */
-		  size_t n;
-		  size_t s;
 		  switch (*++oparg)
 		    {
 		    case 'V':
@@ -4358,20 +4358,24 @@  riscv_ip (char *str, struct riscv_cl_insn *ip, expressionS *imm_expr,
 		      break;
 		    case 'u': /* Integer immediate, 'XpuN@S' ...
 				 N-bit unsigned immediate at bit S.  */
-		      n = strtol (oparg + 1, (char **)&oparg, 10);
-		      if (*oparg != '@')
-			goto unknown_riscv_ip_operand;
-		      s = strtol (oparg + 1, (char **)&oparg, 10);
-		      oparg--;
-		      my_getExpression (imm_expr, asarg, force_reloc);
-		      check_absolute_expr (ip, imm_expr, false);
-		      if (!VALIDATE_U_IMM (imm_expr->X_add_number, n))
-			as_bad (_("improper immediate value (%"PRIu64")"),
-				imm_expr->X_add_number);
-		      INSERT_IMM (n, s, *ip, imm_expr->X_add_number);
-		      imm_expr->X_op = O_absent;
-		      asarg = expr_parse_end;
-		      continue;
+		      {
+			size_t n;
+			size_t s;
+			n = strtol (oparg + 1, (char **)&oparg, 10);
+			if (*oparg != '@')
+			  goto unknown_riscv_ip_operand;
+			s = strtol (oparg + 1, (char **)&oparg, 10);
+			oparg--;
+			my_getExpression (imm_expr, asarg, force_reloc);
+			check_absolute_expr (ip, imm_expr, false);
+			if (!VALIDATE_U_IMM (imm_expr->X_add_number, n))
+			  as_bad (_("improper immediate value (%"PRIu64")"),
+				  imm_expr->X_add_number);
+			INSERT_IMM (n, s, *ip, imm_expr->X_add_number);
+			imm_expr->X_op = O_absent;
+			asarg = expr_parse_end;
+			continue;
+		      }
 		    case 'n': /* Xpn: stride (0-1), paired with Xpx.  */
 		      my_getExpression (imm_expr, asarg, force_reloc);
 		      check_absolute_expr (ip, imm_expr, false);
diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c
index ca0d9bfd121..edb9ce04778 100644
--- a/opcodes/riscv-dis.c
+++ b/opcodes/riscv-dis.c
@@ -924,14 +924,18 @@  print_insn_args (const char *oparg, insn_t l, bfd_vma pc, disassemble_info *info
 		  switch (*++oparg)
 		    {
 		    case 'd':
-		      unsigned vd = EXTRACT_OPERAND (SPACEMIT_IME_VD, l) * 2;
-		      print (info->stream, dis_style_register, "%s",
-			     riscv_vecr_names_numeric[vd]);
+		      {
+			unsigned vd = EXTRACT_OPERAND (SPACEMIT_IME_VD, l) * 2;
+			print (info->stream, dis_style_register, "%s",
+			       riscv_vecr_names_numeric[vd]);
+		      }
 		      break;
 		    case 's':
-		      unsigned vs = EXTRACT_OPERAND (SPACEMIT_IME_VS1, l) * 2;
-		      print (info->stream, dis_style_register, "%s",
-			     riscv_vecr_names_numeric[vs]);
+		      {
+			unsigned vs = EXTRACT_OPERAND (SPACEMIT_IME_VS1, l) * 2;
+			print (info->stream, dis_style_register, "%s",
+			       riscv_vecr_names_numeric[vs]);
+		      }
 		      break;
 		    case 'm':
 		      {