Possible errors in call to output_operand_lossage?

Philipp Thomas pthomas@suse.de
Sun Feb 17 02:06:00 GMT 2002


* Richard Henderson (rth@redhat.com) [20020216 23:15]:

> Exactly why I suggested making output_operand_lossage take printf
> arguments rather than fix them all up.

So I should have asked after your first mail ....
 
> > If so, only those messages that use a single '%' would have to be
> > changed, right?

OK, here's the revised patch, checked by building cc1 for each of the
affected architectures. OK to check in?

2002-02-17  Philipp Thomas  <pthomas@suse.de>

	* final.c (output_operand_lossage): Changed to accept
	printf style arguments. Change calls where necessary.
	* output.h (output_operand_lossage): Change declaration
	accordingly. Update copyright.

	* config/arc/arc.c config/fr30/fr30.c config/m32r/m32r.c
	config/m88k/m88k.c : Adapt all calls to output_operand_lossage.
	Update copyright date where necessary.
	
	* config/i386/i386.c (print_operand): Likewise. Remove use of
	sprintf.

	* config/cris/cris.c (cris_operand_lossage): Likewise.
	Rename parameter so that exgettext recognizes it as
	translatable message.
	(LOSE_AND_RETURN): Rename parameter to msgid.

	* po/gcc.pot: Rebuild.


Index: final.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/final.c,v
retrieving revision 1.240
diff -u -p -r1.240 final.c
--- final.c	2002/02/08 22:20:15	1.240
+++ final.c	2002/02/17 02:19:07
@@ -2965,13 +2965,26 @@ alter_cond (cond)
    In an `asm', it's the user's fault; otherwise, the compiler's fault.  */
 
 void
-output_operand_lossage (msgid)
-     const char *msgid;
+output_operand_lossage VPARAMS ((const char *msgid, ...))
 {
+  char *fmt_string;
+  char *new_message;
+  char *pfx_str;
+  VA_OPEN (ap, msgid);
+  VA_FIXEDARG (ap, const char *, msgid);
+
+  pfx_str = this_is_asm_operands ? _("invalid `asm': ") : "output_operand: ";
+  asprintf (&fmt_string, "%s%s", pfx_str, _(msgid));
+  vasprintf (&new_message, fmt_string, ap);
+  
   if (this_is_asm_operands)
-    error_for_asm (this_is_asm_operands, "invalid `asm': %s", _(msgid));
+    error_for_asm (this_is_asm_operands, "%s", new_message);
   else
-    internal_error ("output_operand: %s", _(msgid));
+    internal_error ("%s", new_message);
+
+  free (fmt_string);
+  free (new_message);
+  VA_CLOSE (ap);
 }
 
 /* Output of assembler code from a template, and its subroutines.  */
@@ -3217,7 +3230,7 @@ output_asm_insn (template, operands)
 	    c = atoi (p);
 
 	    if (! ISDIGIT (*p))
-	      output_operand_lossage ("operand number missing after %-letter");
+	      output_operand_lossage ("operand number missing after %%-letter");
 	    else if (this_is_asm_operands
 		     && (c < 0 || (unsigned int) c >= insn_noperands))
 	      output_operand_lossage ("operand number out of range");
@@ -3309,7 +3322,7 @@ output_asm_label (x)
 	  && NOTE_LINE_NUMBER (x) == NOTE_INSN_DELETED_LABEL))
     ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
   else
-    output_operand_lossage ("`%l' operand isn't a label");
+    output_operand_lossage ("`%%l' operand isn't a label");
 
   assemble_name (asm_out_file, buf);
 }
Index: output.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/output.h,v
retrieving revision 1.93
diff -u -p -r1.93 output.h
--- output.h	2002/02/04 03:03:42	1.93
+++ output.h	2002/02/17 02:19:07
@@ -1,7 +1,7 @@
 /* Declarations for insn-output.c.  These functions are defined in recog.c,
    final.c, and varasm.c.
    Copyright (C) 1987, 1991, 1994, 1997, 1998,
-   1999, 2000, 2001 Free Software Foundation, Inc.
+   1999, 2000, 2001, 2002 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -81,7 +81,7 @@ extern rtx alter_subreg PARAMS ((rtx *))
 
 /* Report inconsistency between the assembler template and the operands.
    In an `asm', it's the user's fault; otherwise, the compiler's fault.  */
-extern void output_operand_lossage  PARAMS ((const char *));
+extern void output_operand_lossage  PARAMS ((const char *, ...)) ATTRIBUTE_PRINTF_1;
 
 /* Output a string of assembler code, substituting insn operands.
    Defined in final.c.  */
Index: config/arc/arc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/arc/arc.c,v
retrieving revision 1.26
diff -u -p -r1.26 arc.c
--- arc.c	2001/12/23 16:07:13	1.26
+++ arc.c	2002/02/17 02:19:07
@@ -1,5 +1,5 @@
 /* Subroutines used for code generation on the Argonaut ARC cpu.
-   Copyright (C) 1994, 1995, 1997, 1998, 1999, 2000, 2001
+   Copyright (C) 1994, 1995, 1997, 1998, 1999, 2000, 2001, 2002
    Free Software Foundation, Inc.
 
 This file is part of GNU CC.
@@ -1706,7 +1706,7 @@ arc_print_operand (file, x, code)
 	  fputc (']', file);
 	}
       else
-	output_operand_lossage ("invalid operand to %R code");
+	output_operand_lossage ("invalid operand to %%R code");
       return;
     case 'S' :
       if ((GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_FLAG (x))
@@ -1738,7 +1738,7 @@ arc_print_operand (file, x, code)
 		   (long)(code == 'L' ? INTVAL (first) : INTVAL (second)));
 	}
       else
-	output_operand_lossage ("invalid operand to %H/%L code");
+	output_operand_lossage ("invalid operand to %%H/%%L code");
       return;
     case 'A' :
       {
@@ -1762,7 +1762,7 @@ arc_print_operand (file, x, code)
 	    fputs (".a", file);
 	}
       else
-	output_operand_lossage ("invalid operand to %U code");
+	output_operand_lossage ("invalid operand to %%U code");
       return;
     case 'V' :
       /* Output cache bypass indicator for a load/store insn.  Volatile memory
@@ -1773,7 +1773,7 @@ arc_print_operand (file, x, code)
 	    fputs (".di", file);
 	}
       else
-	output_operand_lossage ("invalid operand to %V code");
+	output_operand_lossage ("invalid operand to %%V code");
       return;
     case 0 :
       /* Do nothing special.  */
Index: config/fr30/fr30.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/fr30/fr30.c,v
retrieving revision 1.21
diff -u -p -r1.21 fr30.c
--- fr30.c	2002/01/03 17:40:00	1.21
+++ fr30.c	2002/02/17 02:19:07
@@ -1,5 +1,5 @@
 /* FR30 specific functions.
-   Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
    Contributed by Cygnus Solutions.
 
 This file is part of GNU CC.
@@ -480,7 +480,7 @@ fr30_print_operand (file, x, code)
       /* Compute the register name of the second register in a hi/lo
 	 register pair.  */
       if (GET_CODE (x) != REG)
-	output_operand_lossage ("fr30_print_operand: unrecognized %p code");
+	output_operand_lossage ("fr30_print_operand: unrecognized %%p code");
       else
 	fprintf (file, "r%d", REGNO (x) + 1);
       return;
@@ -500,7 +500,7 @@ fr30_print_operand (file, x, code)
 	case GTU: fprintf (file, "hi"); break;
 	case GEU: fprintf (file, "nc");  break;
 	default:
-	  output_operand_lossage ("fr30_print_operand: unrecognized %b code");
+	  output_operand_lossage ("fr30_print_operand: unrecognized %%b code");
 	  break;
 	}
       return;
@@ -521,7 +521,7 @@ fr30_print_operand (file, x, code)
 	case GTU: fprintf (file, "ls"); break;
 	case GEU: fprintf (file, "c"); break;
 	default:
-	  output_operand_lossage ("fr30_print_operand: unrecognized %B code");
+	  output_operand_lossage ("fr30_print_operand: unrecognized %%B code");
 	  break;
 	}
       return;
@@ -529,7 +529,7 @@ fr30_print_operand (file, x, code)
     case 'A':
       /* Print a signed byte value as an unsigned value.  */
       if (GET_CODE (x) != CONST_INT)
-	output_operand_lossage ("fr30_print_operand: invalid operand to %A code");
+	output_operand_lossage ("fr30_print_operand: invalid operand to %%A code");
       else
 	{
 	  HOST_WIDE_INT val;
@@ -546,14 +546,14 @@ fr30_print_operand (file, x, code)
       if (GET_CODE (x) != CONST_INT
 	  || INTVAL (x) < 16
 	  || INTVAL (x) > 32)
-	output_operand_lossage ("fr30_print_operand: invalid %x code");
+	output_operand_lossage ("fr30_print_operand: invalid %%x code");
       else
 	fprintf (file, "%d", INTVAL (x) - 16);
       return;
 
     case 'F':
       if (GET_CODE (x) != CONST_DOUBLE)
-	output_operand_lossage ("fr30_print_operand: invalid %F code");
+	output_operand_lossage ("fr30_print_operand: invalid %%F code");
       else
 	{
 	  REAL_VALUE_TYPE d;
Index: config/i386/i386.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/i386.c,v
retrieving revision 1.362
diff -u -p -r1.362 i386.c
--- i386.c	2002/02/13 22:35:53	1.362
+++ i386.c	2002/02/17 02:19:08
@@ -5862,11 +5862,7 @@ print_operand (file, x, code)
 	    return;
 	  }
 	default:
-	  {
-	    char str[50];
-	    sprintf (str, "invalid operand code `%c'", code);
-	    output_operand_lossage (str);
-	  }
+	    output_operand_lossage ("invalid operand code `%c'", code);
 	}
     }
 
Index: config/m32r/m32r.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/m32r/m32r.c,v
retrieving revision 1.41
diff -u -p -r1.41 m32r.c
--- m32r.c	2002/01/09 11:02:06	1.41
+++ m32r.c	2002/02/17 02:19:08
@@ -1,5 +1,5 @@
 /* Subroutines used for code generation on the Mitsubishi M32R cpu.
-   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001
+   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002
    Free Software Foundation, Inc.
 
 This file is part of GNU CC.
@@ -2245,14 +2245,14 @@ m32r_print_operand (file, x, code)
       if (GET_CODE (x) == REG)
 	fprintf (file, "@+%s", reg_names [REGNO (x)]);
       else
-	output_operand_lossage ("invalid operand to %s code");
+	output_operand_lossage ("invalid operand to %%s code");
       return;
       
     case 'p':
       if (GET_CODE (x) == REG)
 	fprintf (file, "@%s+", reg_names [REGNO (x)]);
       else
-	output_operand_lossage ("invalid operand to %p code");
+	output_operand_lossage ("invalid operand to %%p code");
       return;
 
     case 'R' :
@@ -2275,7 +2275,7 @@ m32r_print_operand (file, x, code)
 	  fputc (')', file);
 	}
       else
-	output_operand_lossage ("invalid operand to %R code");
+	output_operand_lossage ("invalid operand to %%R code");
       return;
 
     case 'H' : /* High word */
@@ -2298,7 +2298,7 @@ m32r_print_operand (file, x, code)
 		   code == 'L' ? INTVAL (first) : INTVAL (second));
 	}
       else
-	output_operand_lossage ("invalid operand to %H/%L code");
+	output_operand_lossage ("invalid operand to %%H/%%L code");
       return;
 
     case 'A' :
@@ -2360,7 +2360,7 @@ m32r_print_operand (file, x, code)
 	  fputc (')', file);
 	  return;
 	default :
-	  output_operand_lossage ("invalid operand to %T/%B code");
+	  output_operand_lossage ("invalid operand to %%T/%%B code");
 	  return;
 	}
       break;
@@ -2375,7 +2375,7 @@ m32r_print_operand (file, x, code)
 	    fputs (".a", file);
 	}
       else
-	output_operand_lossage ("invalid operand to %U code");
+	output_operand_lossage ("invalid operand to %%U code");
       return;
 
     case 'N' :
@@ -2383,7 +2383,7 @@ m32r_print_operand (file, x, code)
       if (GET_CODE (x) == CONST_INT)
 	output_addr_const (file, GEN_INT (- INTVAL (x)));
       else
-	output_operand_lossage ("invalid operand to %N code");
+	output_operand_lossage ("invalid operand to %%N code");
       return;
 
     case 'X' :
Index: config/m88k/m88k.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/m88k/m88k.c,v
retrieving revision 1.56
diff -u -p -r1.56 m88k.c
--- m88k.c	2002/01/03 17:40:04	1.56
+++ m88k.c	2002/02/17 02:19:08
@@ -2879,7 +2879,7 @@ print_operand (file, x, code)
   if (sequencep)
     {
       if (code < 'B' || code > 'E')
-	output_operand_lossage ("%R not followed by %B/C/D/E");
+	output_operand_lossage ("%%R not followed by %%B/C/D/E");
       if (reversep)
 	xc = reverse_condition (xc);
       sequencep = 0;
@@ -2947,43 +2947,43 @@ print_operand (file, x, code)
       value >>= 16;
     case 'x': /* print the lower 16 bits of the integer constant in hex */
       if (xc != CONST_INT)
-	output_operand_lossage ("invalid %x/X value");
+	output_operand_lossage ("invalid %%x/X value");
       fprintf (file, "0x%x", value & 0xffff); return;
 
     case 'H': /* print the low 16 bits of the negated integer constant */
       if (xc != CONST_INT)
-	output_operand_lossage ("invalid %H value");
+	output_operand_lossage ("invalid %%H value");
       value = -value;
     case 'h': /* print the register or low 16 bits of the integer constant */
       if (xc == REG)
 	goto reg;
       if (xc != CONST_INT)
-	output_operand_lossage ("invalid %h value");
+	output_operand_lossage ("invalid %%h value");
       fprintf (file, "%d", value & 0xffff);
       return;
 
     case 'Q': /* print the low 8 bits of the negated integer constant */
       if (xc != CONST_INT)
-	output_operand_lossage ("invalid %Q value");
+	output_operand_lossage ("invalid %%Q value");
       value = -value;
     case 'q': /* print the register or low 8 bits of the integer constant */
       if (xc == REG)
 	goto reg;
       if (xc != CONST_INT)
-	output_operand_lossage ("invalid %q value");
+	output_operand_lossage ("invalid %%q value");
       fprintf (file, "%d", value & 0xff);
       return;
 
     case 'w': /* print the integer constant (X == 32 ? 0 : 32 - X) */
       if (xc != CONST_INT)
-	output_operand_lossage ("invalid %o value");
+	output_operand_lossage ("invalid %%o value");
       fprintf (file, "%d", value == 32 ? 0 : 32 - value);
       return;
 
     case 'p': /* print the logarithm of the integer constant */
       if (xc != CONST_INT
 	  || (value = exact_log2 (value)) < 0)
-	output_operand_lossage ("invalid %p value");
+	output_operand_lossage ("invalid %%p value");
       fprintf (file, "%d", value);
       return;
 
@@ -2996,12 +2996,12 @@ print_operand (file, x, code)
 	register int top, bottom;
 
 	if (xc != CONST_INT)
-	  output_operand_lossage ("invalid %s/S value");
+	  output_operand_lossage ("invalid %%s/S value");
 	/* All the "one" bits must be contiguous.  If so, MASK will be
 	   a power of two or zero.  */
 	mask = (uval | (uval - 1)) + 1;
 	if (!(uval && POWER_OF_2_or_0 (mask)))
-	  output_operand_lossage ("invalid %s/S value");
+	  output_operand_lossage ("invalid %%s/S value");
 	top = mask ? exact_log2 (mask) : 32;
 	bottom = exact_log2 (uval & ~(uval - 1));
 	fprintf (file,"%d<%d>", top - bottom, bottom);
@@ -3012,7 +3012,7 @@ print_operand (file, x, code)
       if (xc == LABEL_REF)
 	output_addr_const (file, x);
       else if (xc != PC)
-	output_operand_lossage ("invalid %P operand");
+	output_operand_lossage ("invalid %%P operand");
       return;
 
     case 'L': /* print 0 or 1 if operand is label_ref and then...  */
@@ -3043,7 +3043,7 @@ print_operand (file, x, code)
 	case LE: fputs ("le0", file); return;
 	case LT: fputs ("lt0", file); return;
 	case GE: fputs ("ge0", file); return;
-	default: output_operand_lossage ("invalid %B value");
+	default: output_operand_lossage ("invalid %%B value");
 	}
 
     case 'C': /* bb0/bb1 branch values for comparisons */
@@ -3060,7 +3060,7 @@ print_operand (file, x, code)
 	case LEU: fputs ("ls", file); return;
 	case LTU: fputs ("lo", file); return;
 	case GEU: fputs ("hs", file); return;
-	default:  output_operand_lossage ("invalid %C value");
+	default:  output_operand_lossage ("invalid %%C value");
 	}
 
     case 'D': /* bcnd branch values for float comparisons */
@@ -3073,7 +3073,7 @@ print_operand (file, x, code)
 	case LE: fputs ("0xe", file); return;
 	case LT: fputs ("0x4", file); return;
 	case GE: fputs ("0xb", file); return;
-	default: output_operand_lossage ("invalid %D value");
+	default: output_operand_lossage ("invalid %%D value");
 	}
 
     case 'E': /* bcnd branch values for special integers */
@@ -3081,12 +3081,12 @@ print_operand (file, x, code)
 	{
 	case EQ: fputs ("0x8", file); return;
 	case NE: fputs ("0x7", file); return;
-	default: output_operand_lossage ("invalid %E value");
+	default: output_operand_lossage ("invalid %%E value");
 	}
 
     case 'd': /* second register of a two register pair */
       if (xc != REG)
-	output_operand_lossage ("`%d' operand isn't a register");
+	output_operand_lossage ("`%%d' operand isn't a register");
       fputs (reg_names[REGNO (x) + 1], file);
       return;
 
@@ -3097,7 +3097,7 @@ print_operand (file, x, code)
 	  return;
 	}
       else if (xc != REG)
-	output_operand_lossage ("invalid %r value");
+	output_operand_lossage ("invalid %%r value");
     case 0:
     name:
       if (xc == REG)
Index: config/cris/cris.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/cris/cris.c,v
retrieving revision 1.14
diff -u -p -r1.14 cris.c
--- cris.c	2002/01/27 03:44:58	1.14
+++ cris.c	2002/02/17 06:30:17
@@ -55,10 +55,10 @@ Boston, MA 02111-1307, USA.  */
 	abort ();						\
     } while (0)
 
-#define LOSE_AND_RETURN(msg, x)			\
+#define LOSE_AND_RETURN(msgid, x)			\
   do						\
     {						\
-      cris_operand_lossage (msg, x);		\
+      cris_operand_lossage (msgid, x);		\
       return;					\
     } while (0)
 
@@ -507,12 +507,12 @@ cris_op_str (x)
    categorization of the error.  */
 
 static void
-cris_operand_lossage (msg, op)
-     const char *msg;
+cris_operand_lossage (msgid, op)
+     const char *msgid;
      rtx op;
 {
   debug_rtx (op);
-  output_operand_lossage (msg);
+  output_operand_lossage ("%s", msgid);
 }
 
 /* Print an index part of an address to file.  */


-- 
Philipp Thomas <pthomas@suse.de>
SuSE Linux AG, Deutscherrnstr. 15-19, D-90429 Nuremberg, Germany



More information about the Gcc-bugs mailing list