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

Mark Zhuang <[email protected]>
Newsgroups gmane.comp.gnu.binutils
Message-ID <[email protected]>
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(-)

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':
 		      {
-- 
2.34.1
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.