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

Jan Beulich <[email protected]>
Newsgroups gmane.comp.gnu.binutils
Message-ID <[email protected]>
On 23.06.2026 14:47, Mark Zhuang wrote:
> From: Mark Zhuang <[email protected]>
> 
> 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.