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 ();
+    }
 
   /* Update crtl->stack_alignment_estimated and use it later to align
      stack.  We check PREFERRED_STACK_BOUNDARY if there may be non-call
@@ -6699,12 +6708,17 @@ pass_expand::execute (function *fun)
        }
     }
 
+  bool expanding_main = false;
+
   /* If this function is `main', emit a call to `__main'
      to run global initializers, etc.  */
   if (DECL_NAME (current_function_decl)
       && MAIN_NAME_P (DECL_NAME (current_function_decl))
       && DECL_FILE_SCOPE_P (current_function_decl))
-    expand_main_function ();
+    {
+      expanding_main = true;
+      expand_main_function ();
+    }
 
   /* Initialize the stack_protect_guard field.  This must happen after the
      call to __main (if any) so that the external decl is initialized.  */
@@ -6847,7 +6861,7 @@ pass_expand::execute (function *fun)
 
   /* Call expand_stack_alignment after finishing all
      updates to crtl->preferred_stack_boundary.  */
-  expand_stack_alignment ();
+  expand_stack_alignment (expanding_main);
 
   /* Fixup REG_EQUIV notes in the prologue if there are tailcalls in this
      function.  */
diff --git a/gcc/testsuite/c-c++-common/pr100575.c 
b/gcc/testsuite/c-c++-common/pr100575.c
new file mode 100644
index 00000000000..e7366a8fe7f
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/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

Reply via email to