From c8f27794b81ede496c04086105ff1a572ccfca47 Mon Sep 17 00:00:00 2001 From: James E Wilson Date: Fri, 19 Aug 2005 14:16:20 -0700 Subject: Fix uninitialized register read problem. * builtins.c (expand_builtin_return_addr): Set current_function_accesses_prior_frames when count != 0. Use frame_pointer_rtx when count == 0. * function.h (struct function): Add accesses_prior_frames field. (current_function_accesses_prior_frames): Define. * reload1.c (init_elim_table): Check current_function_accesses_prior_frames. * doc/tm.texi (INITIAL_FRAME_ADDRESS_RTX): Update docs. From-SVN: r103294 --- gcc/ChangeLog | 11 +++++++++++ gcc/builtins.c | 17 ++++++++++++++++- gcc/doc/tm.texi | 13 +++++-------- gcc/function.h | 5 +++++ gcc/reload1.c | 1 + 5 files changed, 38 insertions(+), 9 deletions(-) (limited to 'gcc') diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8d37b88..8f7da8e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,14 @@ +2005-08-19 James E Wilson + + * builtins.c (expand_builtin_return_addr): Set + current_function_accesses_prior_frames when count != 0. Use + frame_pointer_rtx when count == 0. + * function.h (struct function): Add accesses_prior_frames field. + (current_function_accesses_prior_frames): Define. + * reload1.c (init_elim_table): Check + current_function_accesses_prior_frames. + * doc/tm.texi (INITIAL_FRAME_ADDRESS_RTX): Update docs. + 2005-08-19 Diego Novillo * tree-cfgcleanup.c (cleanup_tree_cfg): Fix flowgraph change diff --git a/gcc/builtins.c b/gcc/builtins.c index d02b1c3..9975b75 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -485,7 +485,22 @@ expand_builtin_return_addr (enum built_in_function fndecl_code, int count) #ifdef INITIAL_FRAME_ADDRESS_RTX rtx tem = INITIAL_FRAME_ADDRESS_RTX; #else - rtx tem = hard_frame_pointer_rtx; + rtx tem; + + /* For a zero count, we don't care what frame address we return, so frame + pointer elimination is OK, and using the soft frame pointer is OK. + For a non-zero count, we require a stable offset from the current frame + pointer to the previous one, so we must use the hard frame pointer, and + we must disable frame pointer elimination. */ + if (count == 0) + tem = frame_pointer_rtx; + else + { + tem = hard_frame_pointer_rtx; + + /* Tell reload not to eliminate the frame pointer. */ + current_function_accesses_prior_frames = 1; + } #endif /* Some machines need special handling before we can access diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index 164bae1..16b48ff 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -2812,14 +2812,11 @@ machines. See @file{function.c} for details. @defmac INITIAL_FRAME_ADDRESS_RTX A C expression whose value is RTL representing the address of the initial - stack frame. This address is passed to @code{RETURN_ADDR_RTX} and -@code{DYNAMIC_CHAIN_ADDRESS}. -If you don't define this macro, the default is to return -@code{hard_frame_pointer_rtx}. -This default is usually correct unless @code{-fomit-frame-pointer} is in -effect. -Define this macro in order to make @code{__builtin_frame_address (0)} and -@code{__builtin_return_address (0)} work even in absence of a hard frame pointer. +stack frame. This address is passed to @code{RETURN_ADDR_RTX} and +@code{DYNAMIC_CHAIN_ADDRESS}. If you don't define this macro, a reasonable +default value will be used. Define this macro in order to make frame pointer +elimination work in the presence of @code{__builtin_frame_address (count)} and +@code{__builtin_return_address (count)} for @code{count} not equal to zero. @end defmac @defmac DYNAMIC_CHAIN_ADDRESS (@var{frameaddr}) diff --git a/gcc/function.h b/gcc/function.h index 11b97c1..c1482ac 100644 --- a/gcc/function.h +++ b/gcc/function.h @@ -394,6 +394,10 @@ struct function GTY(()) either as a subroutine or builtin. */ unsigned int calls_alloca : 1; + /* Nonzero if function being compiled called builtin_return_addr or + builtin_frame_address with non-zero count. */ + unsigned int accesses_prior_frames : 1; + /* Nonzero if the function calls __builtin_eh_return. */ unsigned int calls_eh_return : 1; @@ -483,6 +487,7 @@ extern int trampolines_created; #define current_function_returns_pointer (cfun->returns_pointer) #define current_function_calls_setjmp (cfun->calls_setjmp) #define current_function_calls_alloca (cfun->calls_alloca) +#define current_function_accesses_prior_frames (cfun->accesses_prior_frames) #define current_function_calls_eh_return (cfun->calls_eh_return) #define current_function_is_thunk (cfun->is_thunk) #define current_function_args_info (cfun->args_info) diff --git a/gcc/reload1.c b/gcc/reload1.c index 08e939b..dbe26d4 100644 --- a/gcc/reload1.c +++ b/gcc/reload1.c @@ -3492,6 +3492,7 @@ init_elim_table (void) sp-adjusting insns for this case. */ || (current_function_calls_alloca && EXIT_IGNORE_STACK) + || current_function_accesses_prior_frames || FRAME_POINTER_REQUIRED); num_eliminable = 0; -- cgit v1.1