This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Bug 9862
- From: Steven Bosscher <s dot bosscher at student dot tudelft dot nl>
- To: gcc-patches at gcc dot gnu dot org
- Date: 13 Jul 2003 13:53:38 +0200
- Subject: [PATCH] Bug 9862
Global variables, bah.
The global variables current_function_returns_{value,null} in c-decl.c
are being re-used for the next function after expanding or deferring a
function. But if these variables were set for an offending function,
and this function is deferred, the two variables don't have the
appropriate value anymore when expanding -- in fact, with
-finline-functions they will always have the value of the function that
was parsed last....
Proposed fix is to move the warnings from c_expand_body_1() to
finish_function(). Bootstrapped and regtested on i686-pc-linux-gnu with
only unrelated new regressions (in objc, "tree check: expected
tree_list, have translation_unit_decl"). Test cases go into gcc.dg. OK
for mainline? Also OK for 3.3?
Gr.
Steven
2003-07-13 Steven Bosscher <steven@gcc.gnu.org>
Bug 9862
* c-decl.c (c_expand_body_1): Move warnings from here...
(finish_function): ...to here.
Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.404
diff -c -3 -p -r1.404 c-decl.c
*** c-decl.c 11 Jul 2003 08:33:03 -0000 1.404
--- c-decl.c 13 Jul 2003 10:32:07 -0000
*************** finish_function (int nested, int can_def
*** 6220,6225 ****
--- 6220,6259 ----
&& DECL_INLINE (fndecl))
warning ("no return statement in function returning non-void");
+ /* With just -Wextra, complain only if function returns both with
+ and without a value. */
+ if (extra_warnings
+ && current_function_returns_value
+ && current_function_returns_null)
+ warning ("this function may return with or without a value");
+
+ /* If requested, warn about function definitions where the function will
+ return a value (usually of some struct or union type) which itself will
+ take up a lot of stack space. */
+
+ if (warn_larger_than && !DECL_EXTERNAL (fndecl) && TREE_TYPE (fndecl))
+ {
+ tree ret_type = TREE_TYPE (TREE_TYPE (fndecl));
+
+ if (ret_type && TYPE_SIZE_UNIT (ret_type)
+ && TREE_CODE (TYPE_SIZE_UNIT (ret_type)) == INTEGER_CST
+ && 0 < compare_tree_int (TYPE_SIZE_UNIT (ret_type),
+ larger_than_size))
+ {
+ unsigned int size_as_int
+ = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (ret_type));
+
+ if (compare_tree_int (TYPE_SIZE_UNIT (ret_type), size_as_int) == 0)
+ warning_with_decl (fndecl,
+ "size of return value of `%s' is %u bytes",
+ size_as_int);
+ else
+ warning_with_decl (fndecl,
+ "size of return value of `%s' is larger than %d bytes",
+ larger_than_size);
+ }
+ }
+
/* Clear out memory we no longer need. */
free_after_parsing (cfun);
/* Since we never call rest_of_compilation, we never clear
*************** c_expand_body_1 (tree fndecl, int nested
*** 6416,6455 ****
/* Undo the GC context switch. */
if (nested_p)
ggc_pop_context ();
-
- /* With just -Wextra, complain only if function returns both with
- and without a value. */
- if (extra_warnings
- && current_function_returns_value
- && current_function_returns_null)
- warning ("this function may return with or without a value");
-
- /* If requested, warn about function definitions where the function will
- return a value (usually of some struct or union type) which itself will
- take up a lot of stack space. */
-
- if (warn_larger_than && !DECL_EXTERNAL (fndecl) && TREE_TYPE (fndecl))
- {
- tree ret_type = TREE_TYPE (TREE_TYPE (fndecl));
-
- if (ret_type && TYPE_SIZE_UNIT (ret_type)
- && TREE_CODE (TYPE_SIZE_UNIT (ret_type)) == INTEGER_CST
- && 0 < compare_tree_int (TYPE_SIZE_UNIT (ret_type),
- larger_than_size))
- {
- unsigned int size_as_int
- = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (ret_type));
-
- if (compare_tree_int (TYPE_SIZE_UNIT (ret_type), size_as_int) == 0)
- warning_with_decl (fndecl,
- "size of return value of `%s' is %u bytes",
- size_as_int);
- else
- warning_with_decl (fndecl,
- "size of return value of `%s' is larger than %d bytes",
- larger_than_size);
- }
- }
if (DECL_SAVED_INSNS (fndecl) == 0 && ! nested_p
&& ! flag_inline_trees)
--- 6450,6455 ----
/* Bug 9862 -- Spurious warnings with -finline-functions.
Copyright (C) 2003 Free Software Foundation Inc. */
/* { dg-do compile } */
/* { dg-options "-O -finline-functions" } */
extern int i;
extern int foo (void);
extern int bar (void);
int foo (void)
{
if( i ) return 0;
else return 1;
} /* { dg-bogus "may return with or without value" } */
int bar (void)
{
if( i ) return;
else return 1;
} /* { dg-warning "may return with or without value" } */
/* Bug 9862 -- Spurious warnings with -finline-functions.
Copyright (C) 2003 Free Software Foundation Inc. */
/* { dg-do compile } */
/* { dg-options "-O -finline-functions" } */
extern int i;
extern int foo (void);
extern int bar (void);
int foo (void)
{
if( i ) return;
else return 1;
} /* { dg-warning "may return with or without value" } */
int bar (void)
{
if( i ) return 0;
else return 1;
}