Patch to remove dead code from warn_for_assignment

Joseph S. Myers jsm@polyomino.org.uk
Fri Oct 1 23:23:00 GMT 2004


This C front end patch removes some dead code from warn_for_assignment.  
There is no need to allow for argnum == 0 in argument passing; the 
compiler always knows the number of the argument being converted, and 
since <http://gcc.gnu.org/ml/gcc-patches/2003-11/msg00779.html> this 
information has always been available to warn_for_assignment.  Thus only 
five (four when %E can be used rather than sprintf) rather than seven 
variants of each message passed to warn_for_assignment will be needed for 
proper i18n, as two were dead.

(Likely subsequent patches: fixing %E to work properly for C; changing the 
-Wconversion uses of warn_for_assignment to use warning and %E directly 
(as then they'll only need a single message, so using warn_for_assignment 
is pointless), thereby fixing the bug that -Wconversion -pedantic-errors 
makes the -Wconversion warnings into errors; arranging for 
warn_for_assignment to give a warning rather than a pedwarn for 
diagnostics arising through argument conversion during inlining an 
unprototyped function (really, there shouldn't be such diagnostics from 
inlining at all); using whole sentences (with %E) to improve i18n, and 
potentially improving the English wording.)

Bootstrapped with no regressions on i686-pc-linux-gnu.  Applied to
mainline.

-- 
Joseph S. Myers               http://www.srcf.ucam.org/~jsm28/gcc/
  http://www.srcf.ucam.org/~jsm28/gcc/#c90status - status of C90 for GCC 4.0
    jsm@polyomino.org.uk (personal mail)
    jsm28@gcc.gnu.org (Bugzilla assignments and CCs)

2004-10-02  Joseph S. Myers  <jsm@polyomino.org.uk>

	* c-typeck.c (warn_for_assignment): Don't permit argnum == 0.

diff -rupN GCC.orig/gcc/c-typeck.c GCC/gcc/c-typeck.c
--- GCC.orig/gcc/c-typeck.c	2004-09-30 22:48:36.000000000 +0000
+++ GCC/gcc/c-typeck.c	2004-10-01 12:40:14.000000000 +0000
@@ -3720,8 +3720,7 @@ c_convert_parm_for_inlining (tree parm, 
 
 /* Print a warning using MSGID.
    It gets OPNAME as its one parameter.
-   if OPNAME is null and ARGNUM is 0, it is replaced by "passing arg of `FUNCTION'".
-   Otherwise if OPNAME is null, it is replaced by "passing arg ARGNUM of `FUNCTION'".
+   If OPNAME is null, it is replaced by "passing arg ARGNUM of 'FUNCTION'".
    FUNCTION and ARGNUM are handled specially if we are building an
    Objective-C selector.  */
 
@@ -3739,26 +3738,8 @@ warn_for_assignment (const char *msgid, 
 	  function = selector;
 	  argnum -= 2;
 	}
-      if (argnum == 0)
-	{
-	  if (function)
-	    {
-	      /* Function name is known; supply it.  */
-	      const char *const argstring = _("passing arg of '%s'");
-	      new_opname = (char *) alloca (IDENTIFIER_LENGTH (function)
-				   + strlen (argstring) + 1 + 1);
-	      sprintf (new_opname, argstring,
-		       IDENTIFIER_POINTER (function));
-	    }
-	  else
-	    {
-	      /* Function name unknown (call through ptr).  */
-	      const char *const argnofun = _("passing arg of pointer to function");
-	      new_opname = (char *) alloca (strlen (argnofun) + 1 + 1);
-	      sprintf (new_opname, argnofun);
-	    }
-	}
-      else if (function)
+      gcc_assert (argnum > 0);
+      if (function)
 	{
 	  /* Function name is known; supply it.  */
 	  const char *const argstring = _("passing arg %d of '%s'");



More information about the Gcc-patches mailing list