This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH]: two warnings useful for monitoring stack usage
- To: gcc-patches at gcc dot gnu dot org
- Subject: Re: [PATCH]: two warnings useful for monitoring stack usage
- From: David Whedon <dwhedon at gordian dot com>
- Date: Thu, 1 Feb 2001 11:22:49 -0800
- References: <20010125125414.G42308@ogun.gordian.com> <20010125214101.B28307@daikokuya.demon.co.uk> <20010130184554.Q73656@ogun.gordian.com> <20010131143446.B6284@hg.cs.mu.oz.au>
> It would be nicer to use skip_leading_substring() from toplev.h.
done, I also made one of the warnings more concise.
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.206
diff -c -3 -p -r1.206 c-decl.c
*** c-decl.c 2001/01/31 10:24:39 1.206
--- c-decl.c 2001/02/01 19:16:48
*************** c_decode_option (argc, argv)
*** 744,749 ****
--- 744,775 ----
warn_missing_braces = 0;
else if (!strcmp (p, "-Wmain"))
warn_main = 1;
+ else if ((option_value
+ = skip_leading_substring(p, "-Wframe-size-")))
+ {
+ char *endptr;
+ warn_frame_size = strtol (option_value, &endptr, 10);
+ if (endptr == option_value)
+ {
+ error ("Invalid frame size `%s'", option_value);
+ warn_frame_size_flag = 0;
+ }
+ else
+ warn_frame_size_flag = 1;
+ }
+ else if ((option_value
+ = skip_leading_substring(p, "-Warglist-size-")))
+ {
+ char *endptr;
+ warn_arglist_size = strtol (option_value, &endptr, 10);
+ if (endptr == option_value)
+ {
+ error ("Invalid arglist size `%s'", option_value);
+ 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/02/01 19:16:49
*************** expand_call (exp, target, ignore)
*** 3078,3083 ****
--- 3078,3090 ----
abort ();
#endif
+ if (warn_arglist_size_flag)
+ if (unadjusted_args_size > warn_arglist_size)
+ {
+ warning ("%d byte arglist exceeds user specified limit (%d bytes)",
+ unadjusted_args_size, 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/02/01 19:16:49
*************** 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/02/01 19:16:51
*************** 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/02/01 19:16:52
*************** 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. */