]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
d: Fix gdc -O2 -mavx generates misaligned vmovdqa instruction [PR114171]
authorIain Buclaw <ibuclaw@gdcproject.org>
Sun, 3 Mar 2024 01:26:37 +0000 (02:26 +0100)
committerIain Buclaw <ibuclaw@gdcproject.org>
Sun, 3 Mar 2024 01:26:37 +0000 (02:26 +0100)
PR d/114171

gcc/d/ChangeLog:

* d-codegen.cc (lower_struct_comparison): Keep alignment of original
type in reinterpret cast for comparison.

gcc/testsuite/ChangeLog:

* gdc.dg/torture/pr114171.d: New test.

gcc/d/d-codegen.cc
gcc/testsuite/gdc.dg/torture/pr114171.d [new file with mode: 0644]

index 5bc233928aa86723f6ee4f582a3f3ca3206d9de6..43d7739f8fc6325adf2576e911936a540952ecd3 100644 (file)
@@ -1006,6 +1006,7 @@ lower_struct_comparison (tree_code code, StructDeclaration *sd,
              if (tmode == NULL_TREE)
                tmode = make_unsigned_type (GET_MODE_BITSIZE (mode.require ()));
 
+             tmode = build_aligned_type (tmode, TYPE_ALIGN (stype));
              t1ref = build_vconvert (tmode, t1ref);
              t2ref = build_vconvert (tmode, t2ref);
 
diff --git a/gcc/testsuite/gdc.dg/torture/pr114171.d b/gcc/testsuite/gdc.dg/torture/pr114171.d
new file mode 100644 (file)
index 0000000..0f9ffca
--- /dev/null
@@ -0,0 +1,29 @@
+// { dg-do run }
+// { dg-additional-options "-mavx" { target avx_runtime } }
+// { dg-skip-if "needs gcc/config.d" { ! d_runtime } }
+import gcc.builtins;
+
+struct S1
+{
+    string label;
+}
+
+struct S2
+{
+    ulong pad;
+    S1 label;
+}
+
+pragma(inline, false)
+auto newitem()
+{
+    void *p = __builtin_malloc(S2.sizeof);
+    __builtin_memset(p, 0, S2.sizeof);
+    return cast(S2*) p;
+}
+
+int main()
+{
+    auto bn = newitem();
+    return bn.label is S1.init ? 0 : 1;
+}