On 5/17/21 11:49 AM, H.J. Lu via Gcc-patches wrote:
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.
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;
}
I was taken aback by the choice of -Wmain for this warning but I'm
also not sure any of the existing warning options that have to do
with alignment is a great fit either.
Rather than printing "is too large" I would suggest to print
the maximum:
+ warning_at (DECL_SOURCE_LOCATION (current_function_decl),
+ OPT_Wmain,
+ "argument alignment of %qD exceeds %d",
+ current_function_decl, incoming_stack_boundary);
(I don't think the %qD needs the plus with warning_at.)
I would also recommend to update the manual to mention this new
instance of the warning.
Martin
OK for master?
Thanks.