[PATCH]: two warnings useful for monitoring stack usage
David Whedon
dwhedon@gordian.com
Tue Jan 30 18:46:00 GMT 2001
I've cleaned the patch up a bit, this diff is against current cvs.
-David
Thu Jan 25 20:05:51 PST 2001 David Whedon <dwhedon@gordian.com>
* c-decl.c (c_decode_option) : process new warnings
-Wframe-size-<N> and -Warglist-size-<N>.
* calls.c (expand_call): warn about large argument list
if directed to by command line option.
* flags.h (warn_frame_size, warn_frame_size_flag,
warn_arglist_size, warn_arglist_size_flag) : Declare
externs.
* invoke.texi (Warning Options) : document
-Wframe-size-<N> and -Warglist-size-<N>.
* toplev.c (documented_lang_options) : document
-Wframe-size-<N> and -Warglist-size-<N>.
(rest_of_compilation) : warn about large frames if
directed to by command line option.
Index: gcc/c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.205
diff -c -3 -p -r1.205 c-decl.c
*** c-decl.c 2001/01/30 19:19:38 1.205
--- c-decl.c 2001/01/31 02:29:29
*************** c_decode_option (argc, argv)
*** 744,749 ****
--- 744,775 ----
warn_missing_braces = 0;
else if (!strcmp (p, "-Wmain"))
warn_main = 1;
+ else if (!strncmp (p, "-Wframe-size-", 13))
+ {
+ const char *argstart = &p[13];
+ char *endptr;
+ warn_frame_size = strtol (argstart, &endptr, 10);
+ if (endptr == argstart)
+ {
+ error ("Invalid frame size `%s'", argstart);
+ warn_frame_size_flag = 0;
+ }
+ else
+ warn_frame_size_flag = 1;
+ }
+ else if (!strncmp (p, "-Warglist-size-", 15))
+ {
+ const char *argstart = &p[15];
+ char *endptr;
+ warn_arglist_size = strtol (argstart, &endptr, 10);
+ if (endptr == argstart)
+ {
+ error ("Invalid arg size `%s'", argstart);
+ warn_arglist_size_flag = 0;
+ }
+ else
+ warn_arglist_size_flag = 1;
+ }
else if (!strcmp (p, "-Wno-main"))
warn_main = -1;
else if (!strcmp (p, "-Wsign-compare"))
Index: gcc/calls.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/calls.c,v
retrieving revision 1.175
diff -c -3 -p -r1.175 calls.c
*** calls.c 2001/01/24 19:00:58 1.175
--- calls.c 2001/01/31 02:29:32
*************** expand_call (exp, target, ignore)
*** 3078,3083 ****
--- 3078,3091 ----
abort ();
#endif
+ if (warn_arglist_size_flag)
+ if (unadjusted_args_size > warn_arglist_size)
+ {
+ warning ("%d byte arglist in function call", unadjusted_args_size);
+ warning ("exceeds user specified limit (%d bytes)",
+ warn_arglist_size);
+ }
+
/* Generate the actual call instruction. */
emit_call_1 (funexp, fndecl, funtype, unadjusted_args_size,
adjusted_args_size.constant, struct_value_size,
Index: gcc/flags.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/flags.h,v
retrieving revision 1.57
diff -c -3 -p -r1.57 flags.h
*** flags.h 2001/01/15 22:45:32 1.57
--- flags.h 2001/01/31 02:29:32
*************** extern int warn_missing_noreturn;
*** 142,147 ****
--- 142,159 ----
extern int warn_cast_align;
+ /* Nonzero means warn if a frame is larger that N bytes. The value
+ of N is warn_frame_size. */
+
+ extern int warn_frame_size_flag;
+ extern int warn_frame_size;
+
+ /* Nonzero means warn if a function call pushes more than N bytes
+ onto the stack. The value of N is warn_arglist_size. */
+
+ extern int warn_arglist_size_flag;
+ extern int warn_arglist_size;
+
/* Nonzero means warn about any identifiers that match in the first N
characters. The value N is in `id_clash_len'. */
Index: gcc/invoke.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/invoke.texi,v
retrieving revision 1.270
diff -c -3 -p -r1.270 invoke.texi
*** invoke.texi 2001/01/23 21:35:15 1.270
--- invoke.texi 2001/01/31 02:29:36
*************** in the following sections.
*** 193,206 ****
@xref{Warning Options,,Options to Request or Suppress Warnings}.
@gccoptlist{
-fsyntax-only -pedantic -pedantic-errors @gol
! -w -W -Wall -Waggregate-return @gol
-Wcast-align -Wcast-qual -Wchar-subscripts -Wcomment @gol
-Wconversion -Wdisabled-optimization -Werror @gol
-Wfloat-equal -Wformat -Wformat=2 @gol
-Wformat-nonliteral -Wformat-security @gol
-Wid-clash-@var{len} -Wimplicit -Wimplicit-int @gol
-Wimplicit-function-declaration @gol
! -Werror-implicit-function-declaration @gol
-Wimport -Winline @gol
-Wlarger-than-@var{len} -Wlong-long @gol
-Wmain -Wmissing-declarations @gol
--- 193,206 ----
@xref{Warning Options,,Options to Request or Suppress Warnings}.
@gccoptlist{
-fsyntax-only -pedantic -pedantic-errors @gol
! -w -W -Wall -Waggregate-return -Warglist-size-@var{n} @gol
-Wcast-align -Wcast-qual -Wchar-subscripts -Wcomment @gol
-Wconversion -Wdisabled-optimization -Werror @gol
-Wfloat-equal -Wformat -Wformat=2 @gol
-Wformat-nonliteral -Wformat-security @gol
-Wid-clash-@var{len} -Wimplicit -Wimplicit-int @gol
-Wimplicit-function-declaration @gol
! -Werror-implicit-function-declaration -Wframe-size-@var{n} @gol
-Wimport -Winline @gol
-Wlarger-than-@var{len} -Wlong-long @gol
-Wmain -Wmissing-declarations @gol
*************** Warn if @samp{long long} type is used.
*** 2291,2296 ****
--- 2291,2307 ----
the warning messages, use @samp{-Wno-long-long}. Flags
@samp{-Wlong-long} and @samp{-Wno-long-long} are taken into account
only when @samp{-pedantic} flag is used.
+
+ @item -Wframe-size-@var{n}
+ Warn if a frame uses greater than @var{n} bytes. This warning can be useful
+ when stack space is limited, as is typical in embedded environments. This
+ warning, and also @samp{-Warglist-size-@var{n}}, can help locate functions
+ who may contribute to a stack overrun.
+
+ @item -Warglist-size-@var{n}
+ Warn if function argument list uses greater than @var{n} bytes. As with
+ @samp{-Wframe-size-@var{n}}, this warning can help locate functions who
+ may contribute to a stack overrun.
@item -Wdisabled-optimization
Warn if a requested optimization pass is disabled. This warning does
Index: gcc/toplev.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/toplev.c,v
retrieving revision 1.419
diff -c -3 -p -r1.419 toplev.c
*** toplev.c 2001/01/30 19:19:39 1.419
--- toplev.c 2001/01/31 02:29:37
*************** documented_lang_options[] =
*** 1254,1259 ****
--- 1254,1263 ----
{ "-Wlong-long","" },
{ "-Wno-long-long", "Do not warn about using 'long long' when -pedantic" },
{ "-Wmain", "Warn about suspicious declarations of main" },
+ { "-Wframe-size-<N> ",
+ "Warn if frame uses greater than <N> bytes." },
+ { "-Wlarglist-size-<N> ",
+ "Warn if function argument list uses greater than <N> bytes." },
{ "-Wno-main", "" },
{ "-Wmissing-braces",
"Warn about possibly missing braces around initialisers" },
*************** int warn_return_type;
*** 1396,1401 ****
--- 1400,1417 ----
int warn_cast_align;
+ /* Nonzero means warn if a frame is larger that N bytes. The value
+ of N is warn_frame_size. */
+
+ int warn_frame_size_flag=0;
+ int warn_frame_size;
+
+ /* Nonzero means warn if a function call pushes more than N bytes
+ onto the stack. The value of N is warn_arglist_size. */
+
+ int warn_arglist_size_flag=0;
+ int warn_arglist_size;
+
/* Nonzero means warn about any identifiers that match in the first N
characters. The value N is in `id_clash_len'. */
*************** rest_of_compilation (decl)
*** 3674,3679 ****
--- 3690,3700 ----
/* Now we know that this can't throw; set the flag for the benefit
of other functions later in this translation unit. */
TREE_NOTHROW (current_function_decl) = 1;
+
+ if (warn_frame_size_flag)
+ if (get_frame_size () > warn_frame_size)
+ warning ("%d byte frame exceeds user specified limit (%d bytes)",
+ get_frame_size (), warn_frame_size);
/* Now turn the rtl into assembler code. */
More information about the Gcc-patches
mailing list