[binutils-gdb/binutils-2_47-branch] loongarch gcc-4.9 build error

Alan Modra via Binutils-cvs <[email protected]> Fri, 17 Jul 2026 00:16:42 +0000 (GMT)
Newsgroups gmane.comp.gnu.binutils.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=c7b5b05508ef05f74167bc9a8fddb97553394fb9

commit c7b5b05508ef05f74167bc9a8fddb97553394fb9
Author: Alan Modra <[email protected]>
Date:   Fri Jul 17 09:37:37 2026 +0930

    loongarch gcc-4.9 build error
    
    gas/config/tc-loongarch.c: In function ‘md_apply_fix’:
    gas/config/tc-loongarch.c:1886:7: error: a label can only be part of a statement and a declaration is not a statement
           unsigned int subtype;
           ^
    
            * config/tc-loongarch.c (md_apply_fix <BFD_RELOC_LARCH_CFA>):
            Avoid gcc-4.9 error.
    
    (cherry picked from commit d36b7ef85a30cda5ea19110920f61727be2fd984)

Diff:
---
 gas/config/tc-loongarch.c | 122 +++++++++++++++++++++++-----------------------
 1 file changed, 62 insertions(+), 60 deletions(-)

diff --git a/gas/config/tc-loongarch.c b/gas/config/tc-loongarch.c
index e67394c460c..bd7d8dabb7a 100644
--- a/gas/config/tc-loongarch.c
+++ b/gas/config/tc-loongarch.c
@@ -1883,70 +1883,72 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
       break;
 
     case BFD_RELOC_LARCH_CFA:
-      unsigned int subtype;
-      fragS *opfrag = (fragS *) fixP->fx_frag->fr_opcode;
-      subtype = bfd_get_8 (NULL, opfrag->fr_literal + fixP->fx_where);
-
-      /* Update to the real size after relax_segment.  */
-      if (subtype == DW_CFA_advance_loc2)
-	fixP->fx_size = 2;
-      if (subtype == DW_CFA_advance_loc4)
-	fixP->fx_size = 4;
-
-      if (fixP->fx_addsy && fixP->fx_subsy)
-	{
-	  fixP->fx_next = xmemdup (fixP, sizeof (*fixP), sizeof (*fixP));
-	  fixP->fx_next->fx_addsy = fixP->fx_subsy;
-	  fixP->fx_next->fx_subsy = NULL;
-	  fixP->fx_next->fx_offset = 0;
-	  fixP->fx_subsy = NULL;
-
-	  offsetT loc;
-	  loc = fixP->fx_frag->fr_fix - (subtype & 7);
-	  switch (subtype)
-	    {
-	    case DW_CFA_advance_loc1:
-	      fixP->fx_where = loc + 1;
-	      fixP->fx_next->fx_where = loc + 1;
-	      fixP->fx_r_type = BFD_RELOC_LARCH_ADD8;
-	      fixP->fx_next->fx_r_type = BFD_RELOC_LARCH_SUB8;
-	      md_number_to_chars (buf+1, 0, fixP->fx_size);
-	      break;
-
-	    case DW_CFA_advance_loc2:
-	      fixP->fx_where = loc + 1;
-	      fixP->fx_next->fx_where = loc + 1;
-	      fixP->fx_r_type = BFD_RELOC_LARCH_ADD16;
-	      fixP->fx_next->fx_r_type = BFD_RELOC_LARCH_SUB16;
-	      md_number_to_chars (buf+1, 0, fixP->fx_size);
-	      break;
+      {
+	unsigned int subtype;
+	fragS *opfrag = (fragS *) fixP->fx_frag->fr_opcode;
+	subtype = bfd_get_8 (NULL, opfrag->fr_literal + fixP->fx_where);
 
-	    case DW_CFA_advance_loc4:
-	      fixP->fx_where = loc;
-	      fixP->fx_next->fx_where = loc;
-	      fixP->fx_r_type = BFD_RELOC_LARCH_ADD32;
-	      fixP->fx_next->fx_r_type = BFD_RELOC_LARCH_SUB32;
-	      md_number_to_chars (buf+1, 0, fixP->fx_size);
-	      break;
+	/* Update to the real size after relax_segment.  */
+	if (subtype == DW_CFA_advance_loc2)
+	  fixP->fx_size = 2;
+	if (subtype == DW_CFA_advance_loc4)
+	  fixP->fx_size = 4;
 
-	    default:
-	      if (subtype < 0x80 && (subtype & 0x40))
-		{
-		  /* DW_CFA_advance_loc.  */
-		  fixP->fx_frag = opfrag;
-		  fixP->fx_next->fx_frag = fixP->fx_frag;
-		  fixP->fx_r_type = BFD_RELOC_LARCH_ADD6;
-		  fixP->fx_next->fx_r_type = BFD_RELOC_LARCH_SUB6;
-		  md_number_to_chars (buf, 0x40, fixP->fx_size);
+	if (fixP->fx_addsy && fixP->fx_subsy)
+	  {
+	    fixP->fx_next = xmemdup (fixP, sizeof (*fixP), sizeof (*fixP));
+	    fixP->fx_next->fx_addsy = fixP->fx_subsy;
+	    fixP->fx_next->fx_subsy = NULL;
+	    fixP->fx_next->fx_offset = 0;
+	    fixP->fx_subsy = NULL;
+
+	    offsetT loc;
+	    loc = fixP->fx_frag->fr_fix - (subtype & 7);
+	    switch (subtype)
+	      {
+	      case DW_CFA_advance_loc1:
+		fixP->fx_where = loc + 1;
+		fixP->fx_next->fx_where = loc + 1;
+		fixP->fx_r_type = BFD_RELOC_LARCH_ADD8;
+		fixP->fx_next->fx_r_type = BFD_RELOC_LARCH_SUB8;
+		md_number_to_chars (buf+1, 0, fixP->fx_size);
+		break;
+
+	      case DW_CFA_advance_loc2:
+		fixP->fx_where = loc + 1;
+		fixP->fx_next->fx_where = loc + 1;
+		fixP->fx_r_type = BFD_RELOC_LARCH_ADD16;
+		fixP->fx_next->fx_r_type = BFD_RELOC_LARCH_SUB16;
+		md_number_to_chars (buf+1, 0, fixP->fx_size);
+		break;
+
+	      case DW_CFA_advance_loc4:
+		fixP->fx_where = loc;
+		fixP->fx_next->fx_where = loc;
+		fixP->fx_r_type = BFD_RELOC_LARCH_ADD32;
+		fixP->fx_next->fx_r_type = BFD_RELOC_LARCH_SUB32;
+		md_number_to_chars (buf+1, 0, fixP->fx_size);
+		break;
+
+	      default:
+		if (subtype < 0x80 && (subtype & 0x40))
+		  {
+		    /* DW_CFA_advance_loc.  */
+		    fixP->fx_frag = opfrag;
+		    fixP->fx_next->fx_frag = fixP->fx_frag;
+		    fixP->fx_r_type = BFD_RELOC_LARCH_ADD6;
+		    fixP->fx_next->fx_r_type = BFD_RELOC_LARCH_SUB6;
+		    md_number_to_chars (buf, 0x40, fixP->fx_size);
 		  }
-	      else
-		as_fatal (_("internal: bad CFA value #%d"), subtype);
-	      break;
-	    }
-	}
+		else
+		  as_fatal (_("internal: bad CFA value #%d"), subtype);
+		break;
+	      }
+	  }
 
-      if (fixP->fx_addsy == NULL)
-	fixP->fx_done = 1;
+	if (fixP->fx_addsy == NULL)
+	  fixP->fx_done = 1;
+      }
       break;
 
     case BFD_RELOC_LARCH_B16: