defer_stack_allocation and expand_one_stack_var_1 computed a
local's stack alignment in two different ways, so a variable the former
considered small enough to allocate immediately could trip the
large-alignment assert in the latter (PR target/120192).  Use
align_local_variable in both.

Regtested on x86_64-pc-linux-gnu and, under QEMU, on
aarch64-unknown-linux-gnu, with no new failures.

gcc/ChangeLog:

        PR target/120192
        * cfgexpand.cc (defer_stack_allocation): Use align_local_variable
        to compute the alignment, matching expand_one_stack_var_1.

gcc/testsuite/ChangeLog:

        PR target/120192
        * gcc.target/i386/pr120192.c: New test.

Signed-off-by: Oleg Tolmatcev <[email protected]>
---
 gcc/cfgexpand.cc                         | 8 +++++---
 gcc/testsuite/gcc.target/i386/pr120192.c | 9 +++++++++
 2 files changed, 14 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr120192.c

diff --git a/gcc/cfgexpand.cc b/gcc/cfgexpand.cc
index 128cfc7768..245ba357b5 100644
--- a/gcc/cfgexpand.cc
+++ b/gcc/cfgexpand.cc
@@ -1995,9 +1995,11 @@ defer_stack_allocation (tree var, bool toplevel)
   if (flag_stack_protect || asan_sanitize_stack_p ())
     return true;
 
-  unsigned int align = TREE_CODE (var) == SSA_NAME
-    ? TYPE_ALIGN (TREE_TYPE (var))
-    : DECL_ALIGN (var);
+  /* Use the same effective alignment that expand_one_stack_var_1 would use.
+     If that alignment exceeds MAX_SUPPORTED_STACK_ALIGNMENT, defer
+     the variable so that expand_stack_vars handles its large alignment,
+     rather than calling expand_one_stack_var_1 and failing its assertion.  */
+  unsigned int align = align_local_variable (var, false) * BITS_PER_UNIT;
 
   /* We handle "large" alignment via dynamic allocation.  We want to handle
      this extra complication in only one place, so defer them.  */
diff --git a/gcc/testsuite/gcc.target/i386/pr120192.c 
b/gcc/testsuite/gcc.target/i386/pr120192.c
new file mode 100644
index 0000000000..9cb60a69e9
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr120192.c
@@ -0,0 +1,9 @@
+/* PR target/120192 */
+/* { dg-do compile { target x86_64-*-mingw* } } */
+/* { dg-options "-O0 -mavx" } */
+
+typedef char a;
+void b() {
+  typedef a c __attribute__((vector_size(32), aligned));
+  c d = {};
+}
-- 
2.55.0.windows.5

Reply via email to