public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-9269] d: Fix closure fields don't get same alignment as local variable [PR109144]
@ 2023-03-16 11:38 Iain Buclaw
  0 siblings, 0 replies; only message in thread
From: Iain Buclaw @ 2023-03-16 11:38 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:2ca6dba641fa56ce70c3e1c78729389b3ed40076

commit r12-9269-g2ca6dba641fa56ce70c3e1c78729389b3ed40076
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date:   Thu Mar 16 01:07:02 2023 +0100

    d: Fix closure fields don't get same alignment as local variable [PR109144]
    
    Local variables with both non-local references and explicit alignment
    did not propagate their alignment to either the closure field or closure
    frame type, resulting in the closure being misaligned. This is now
    correctly set-up when building the frame type.
    
            PR d/109144
    
    gcc/d/ChangeLog:
    
            * d-codegen.cc (build_frame_type): Set frame field and type alignment.
    
    gcc/testsuite/ChangeLog:
    
            * gdc.dg/torture/pr109144.d: New test.
    
    (cherry picked from commit 46c4be98d1e759a406069487e5dbaad0346e7e7d)

Diff:
---
 gcc/d/d-codegen.cc                      | 5 +++++
 gcc/testsuite/gdc.dg/torture/pr109144.d | 9 +++++++++
 2 files changed, 14 insertions(+)

diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index 0f2110ec7c1..dfeae831801 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -2720,6 +2720,11 @@ build_frame_type (tree ffi, FuncDeclaration *fd)
       TREE_ADDRESSABLE (field) = TREE_ADDRESSABLE (vsym);
       DECL_NONADDRESSABLE_P (field) = !TREE_ADDRESSABLE (vsym);
       TREE_THIS_VOLATILE (field) = TREE_THIS_VOLATILE (vsym);
+      SET_DECL_ALIGN (field, DECL_ALIGN (vsym));
+
+      /* Update alignment for frame record type.  */
+      if (TYPE_ALIGN (frame_rec_type) < DECL_ALIGN (field))
+	SET_TYPE_ALIGN (frame_rec_type, DECL_ALIGN (field));
 
       if (DECL_LANG_NRVO (vsym))
 	{
diff --git a/gcc/testsuite/gdc.dg/torture/pr109144.d b/gcc/testsuite/gdc.dg/torture/pr109144.d
new file mode 100644
index 00000000000..32d3af7cd45
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/torture/pr109144.d
@@ -0,0 +1,9 @@
+// { dg-do run }
+// { dg-skip-if "needs gcc/config.d" { ! d_runtime } }
+void main()
+{
+    align(128) byte var;
+    assert((cast(size_t) &var) % 128 == 0);
+    var = 73;
+    assert((() => var)() == 73);
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-03-16 11:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-16 11:38 [gcc r12-9269] d: Fix closure fields don't get same alignment as local variable [PR109144] Iain Buclaw

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).