On 5/13/21 3:37 PM, H.J. Lu via Gcc-patches wrote:
> Warn for excessive argument alignment in main instead of ICE.
>
> gcc/
>
> PR c/100575
> * cfgexpand.c (expand_stack_alignment): Add a bool argument for
> expanding main. Warn for excessive argument alignment in main.
> (pass_expand::execute): Pass true to expand_stack_alignment when
> expanding main.
>
> gcc/testsuite/
>
> PR c/100575
> * c-c++-common/pr100575.c: New test.
> ---
> gcc/cfgexpand.c | 26 ++++++++++++++++++++------
> gcc/testsuite/c-c++-common/pr100575.c | 11 +++++++++++
> 2 files changed, 31 insertions(+), 6 deletions(-)
> create mode 100644 gcc/testsuite/c-c++-common/pr100575.c
>
> diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c
> index e3814ee9d06..50ccb720e6c 100644
> --- a/gcc/cfgexpand.c
> +++ b/gcc/cfgexpand.c
> @@ -6363,7 +6363,7 @@ discover_nonconstant_array_refs (void)
> virtual_incoming_args_rtx with the virtual register. */
>
> static void
> -expand_stack_alignment (void)
> +expand_stack_alignment (bool expanding_main)
> {
> rtx drap_rtx;
> unsigned int preferred_stack_boundary;
> @@ -6385,9 +6385,18 @@ expand_stack_alignment (void)
> if (targetm.calls.update_stack_boundary)
> targetm.calls.update_stack_boundary ();
>
> - /* The incoming stack frame has to be aligned at least at
> - parm_stack_boundary. */
> - gcc_assert (crtl->parm_stack_boundary <= INCOMING_STACK_BOUNDARY);
> + if (crtl->parm_stack_boundary > INCOMING_STACK_BOUNDARY)
> + {
> + /* The incoming stack frame has to be aligned at least at
> + parm_stack_boundary. NB: The incoming stack frame alignment
> + for main is fixed. */
> + if (expanding_main)
> + warning_at (DECL_SOURCE_LOCATION (current_function_decl),
> + OPT_Wmain, "argument alignment of %q+D is too large",
> + current_function_decl);
> + else
> + gcc_unreachable ();
> + }
Could you do this instead in ix86_minimum_incoming_stack_boundary
/* The incoming stack frame has to be aligned at least at
parm_stack_boundary. */
if (incoming_stack_boundary < crtl->parm_stack_boundary)
incoming_stack_boundary = crtl->parm_stack_boundary;
/* Stack at entrance of main is aligned by runtime. We use the
smallest incoming stack boundary. */
if (incoming_stack_boundary > MAIN_STACK_BOUNDARY
&& DECL_NAME (current_function_decl)
&& MAIN_NAME_P (DECL_NAME (current_function_decl))
&& DECL_FILE_SCOPE_P (current_function_decl))
incoming_stack_boundary = MAIN_STACK_BOUNDARY;
maybe just repeat this after incoming_stack_boundary is set to
MAIN_STACK_BOUNDARY:
/* The incoming stack frame has to be aligned at least at
parm_stack_boundary. */
if (incoming_stack_boundary < crtl->parm_stack_boundary)
incoming_stack_boundary = crtl->parm_stack_boundary;
and print the warning here?
Thanks
Bernd.