This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[3.4/mainline] PR 15004
- From: Jan Hubicka <jh at suse dot cz>
- To: gcc-patches at gcc dot gnu dot org, rth at redhat dot com
- Date: Wed, 28 Apr 2004 16:02:01 +0200
- Subject: [3.4/mainline] PR 15004
Hi,
this patch makes the warning to be chhecked on analysis time instaed of
end of compilation so we get the warning even for functions never
compiled.
Honza
/* { dg-do compile } */
/* { dg-options "-O3 -Wunused-parameter" } */
static int t(int i) /* { dg-warning "unused parameter" "unused parameter warning" } */
{
return 0;
}
int tt()
{
return t(0);
}
2004-04-28 Jan Hubicka <jh@suse.cz>
PR c/15004
* function.c (do_warn_unused_parameter): Break out form ...
(expand_function_end): ... here; warn only when not using cgraphunit.
* function.h (do_warn_unused_parameter): Declare.
* cgraphunit.c: Include function.h.
(cgraph_finalize_function): Do unused parameter warning.
* Makefile.in (cgraphunit.o): Depend on function.h
Index: function.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/function.c,v
retrieving revision 1.510
diff -c -3 -p -r1.510 function.c
*** function.c 9 Apr 2004 01:38:12 -0000 1.510
--- function.c 18 Apr 2004 21:53:10 -0000
*************** use_return_register (void)
*** 6913,6918 ****
--- 6913,6931 ----
diddle_return_value (do_use_return_reg, NULL);
}
+ /* Possibly warn about unused parameters. */
+ void
+ do_warn_unused_parameter (tree fn)
+ {
+ tree decl;
+
+ for (decl = DECL_ARGUMENTS (fn);
+ decl; decl = TREE_CHAIN (decl))
+ if (!TREE_USED (decl) && TREE_CODE (decl) == PARM_DECL
+ && DECL_NAME (decl) && !DECL_ARTIFICIAL (decl))
+ warning ("%Junused parameter '%D'", decl, decl);
+ }
+
static GTY(()) rtx initial_trampoline;
/* Generate RTL for the end of the current function. */
*************** expand_function_end (void)
*** 7001,7017 ****
}
}
! /* Possibly warn about unused parameters. */
! if (warn_unused_parameter)
! {
! tree decl;
!
! for (decl = DECL_ARGUMENTS (current_function_decl);
! decl; decl = TREE_CHAIN (decl))
! if (! TREE_USED (decl) && TREE_CODE (decl) == PARM_DECL
! && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl))
! warning ("%Junused parameter '%D'", decl, decl);
! }
/* Delete handlers for nonlocal gotos if nothing uses them. */
if (nonlocal_goto_handler_slots != 0
--- 7014,7025 ----
}
}
! /* Possibly warn about unused parameters.
! When frontend does unit-at-a-time, the warning is already
! issued at finalization time. */
! if (warn_unused_parameter
! && !lang_hooks.callgraph.expand_function)
! do_warn_unused_parameter (current_function_decl);
/* Delete handlers for nonlocal gotos if nothing uses them. */
if (nonlocal_goto_handler_slots != 0
Index: function.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/function.h,v
retrieving revision 1.112
diff -c -3 -p -r1.112 function.h
*** function.h 1 Apr 2004 23:27:59 -0000 1.112
--- function.h 18 Apr 2004 21:53:10 -0000
*************** extern const char *current_function_name
*** 648,651 ****
--- 648,653 ----
/* Called once, at initialization, to initialize function.c. */
extern void init_function_once (void);
+ extern void do_warn_unused_parameter (tree);
+
#endif /* GCC_FUNCTION_H */
Index: cgraphunit.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cgraphunit.c,v
retrieving revision 1.55
diff -c -3 -p -r1.55 cgraphunit.c
*** cgraphunit.c 1 Apr 2004 23:27:58 -0000 1.55
--- cgraphunit.c 19 Apr 2004 10:32:22 -0000
*************** Software Foundation, 59 Temple Place - S
*** 183,188 ****
--- 183,189 ----
#include "fibheap.h"
#include "c-common.h"
#include "intl.h"
+ #include "function.h"
#define INSNS_PER_CALL 10
*************** cgraph_finalize_function (tree decl, boo
*** 377,382 ****
--- 377,386 ----
early then. */
if (DECL_EXTERNAL (decl))
DECL_STRUCT_FUNCTION (decl) = NULL;
+
+ /* Possibly warn about unused parameters. */
+ if (warn_unused_parameter)
+ do_warn_unused_parameter (decl);
}
/* Walk tree and record all calls. Called via walk_tree. */
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Makefile.in,v
retrieving revision 1.1268
diff -c -3 -p -r1.1268 Makefile.in
*** Makefile.in 1 Apr 2004 23:27:56 -0000 1.1268
--- Makefile.in 19 Apr 2004 10:33:16 -0000
*************** cgraph.o : cgraph.c $(CONFIG_H) $(SYSTEM
*** 1657,1663 ****
langhooks.h toplev.h flags.h $(GGC_H) $(TARGET_H) cgraph.h gt-cgraph.h \
output.h intl.h
cgraphunit.o : cgraphunit.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
! langhooks.h tree-inline.h toplev.h flags.h $(GGC_H) $(TARGET_H) cgraph.h intl.h
coverage.o : coverage.c gcov-io.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
$(TM_H) $(RTL_H) $(TREE_H) flags.h output.h $(REGS_H) $(EXPR_H) function.h \
toplev.h $(GGC_H) $(TARGET_H) langhooks.h $(COVERAGE_H) libfuncs.h \
--- 1657,1664 ----
langhooks.h toplev.h flags.h $(GGC_H) $(TARGET_H) cgraph.h gt-cgraph.h \
output.h intl.h
cgraphunit.o : cgraphunit.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
! langhooks.h tree-inline.h toplev.h flags.h $(GGC_H) $(TARGET_H) cgraph.h intl.h \
! function.h
coverage.o : coverage.c gcov-io.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
$(TM_H) $(RTL_H) $(TREE_H) flags.h output.h $(REGS_H) $(EXPR_H) function.h \
toplev.h $(GGC_H) $(TARGET_H) langhooks.h $(COVERAGE_H) libfuncs.h \
Index: builtins.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/builtins.c,v
retrieving revision 1.309
diff -c -3 -r1.309 builtins.c
*** builtins.c 15 Apr 2004 22:35:34 -0000 1.309
--- builtins.c 19 Apr 2004 16:34:47 -0000
***************
*** 5944,5950 ****
type. Return NULL_TREE if no simplification can be made. */
static tree
! fold_builtin_cabs (tree fndecl, tree arglist, tree type)
{
tree arg;
--- 5944,5950 ----
type. Return NULL_TREE if no simplification can be made. */
static tree
! fold_builtin_cabs (tree fndecl ATTRIBUTE_UNUSED, tree arglist, tree type)
{
tree arg;