On Thu, May 13, 2021 at 9:15 AM Bernd Edlinger <bernd.edlin...@hotmail.de> wrote: > > 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
Fixed. > /* 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? > Here is the v2 patch to issue a warning in ix86_minimum_incoming_stack_boundary. OK for master? Thanks. -- H.J.
From c28fb9d5c6f6d68ac137e461aada23f8e10352bb Mon Sep 17 00:00:00 2001 From: "H.J. Lu" <hjl.to...@gmail.com> Date: Thu, 13 May 2021 06:31:04 -0700 Subject: [PATCH v2] x86: Warn for excessive argument alignment in main Warn for excessive argument alignment in main instead of ICE. gcc/ PR c/100575 * config/i386/i386.c (ix86_minimum_incoming_stack_boundary): Warn for excessive argument alignment in main. gcc/testsuite/ PR c/100575 * gcc.target/i386/pr100575.c: New test. --- gcc/config/i386/i386.c | 12 +++++++++++- gcc/testsuite/gcc.target/i386/pr100575.c | 11 +++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr100575.c diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index befe69e5eeb..85283d23bd3 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -7272,7 +7272,17 @@ ix86_minimum_incoming_stack_boundary (bool sibcall) && 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; + { + incoming_stack_boundary = MAIN_STACK_BOUNDARY; + if (crtl->parm_stack_boundary > incoming_stack_boundary) + { + warning_at (DECL_SOURCE_LOCATION (current_function_decl), + OPT_Wmain, + "argument alignment of %q+D is too large", + current_function_decl); + incoming_stack_boundary = crtl->parm_stack_boundary; + } + } return incoming_stack_boundary; } diff --git a/gcc/testsuite/gcc.target/i386/pr100575.c b/gcc/testsuite/gcc.target/i386/pr100575.c new file mode 100644 index 00000000000..e7366a8fe7f --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr100575.c @@ -0,0 +1,11 @@ +/* { dg-do run } */ +/* { dg-options "-Wall -Wno-psabi" } */ + +int +main (int __attribute__((vector_size(1 << 29))) argc, + char **argv) +/* { dg-warning "first argument of" "" { target *-*-* } .-2 } */ +/* { dg-warning "argument alignment of" "" { target *-*-* } .-3 } */ +{ + return 0; +} -- 2.31.1