]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: alignment of local typedef in template [PR65211]
authorJason Merrill <jason@redhat.com>
Thu, 14 Apr 2022 01:56:03 +0000 (21:56 -0400)
committerJason Merrill <jason@redhat.com>
Fri, 13 May 2022 17:39:31 +0000 (13:39 -0400)
Because common_handle_aligned_attribute only applies the alignment to the
TREE_TYPE of a typedef, not the DECL_ORIGINAL_TYPE, we need to copy it
explicitly in tsubst.

PR c++/65211

gcc/cp/ChangeLog:

* pt.c (tsubst_decl) [TYPE_DECL]: Copy TYPE_ALIGN.

gcc/testsuite/ChangeLog:

* g++.target/i386/vec-tmpl1.C: New test.

gcc/cp/pt.c
gcc/testsuite/g++.target/i386/vec-tmpl1.C [new file with mode: 0644]

index 62ea5c4d8e557dbb6be85e74c4ba4ffb78a50490..eeee23181fc6377ba13de3dcb82dbd0362489577 100644 (file)
@@ -14095,6 +14095,13 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain)
          {
            DECL_ORIGINAL_TYPE (r) = NULL_TREE;
            set_underlying_type (r);
+
+           /* common_handle_aligned_attribute doesn't apply the alignment
+              to DECL_ORIGINAL_TYPE.  */
+           if (TYPE_USER_ALIGN (TREE_TYPE (t)))
+             TREE_TYPE (r) = build_aligned_type (TREE_TYPE (r),
+                                                 TYPE_ALIGN (TREE_TYPE (t)));
+
            if (TYPE_DECL_ALIAS_P (r))
              /* An alias template specialization can be dependent
                 even if its underlying type is not.  */
diff --git a/gcc/testsuite/g++.target/i386/vec-tmpl1.C b/gcc/testsuite/g++.target/i386/vec-tmpl1.C
new file mode 100644 (file)
index 0000000..e0865e3
--- /dev/null
@@ -0,0 +1,17 @@
+// PR c++/65211
+// { dg-additional-options "-Wno-psabi" }
+// { dg-final { scan-assembler-not "movdqa" } }
+
+typedef unsigned v4ui __attribute__ ((vector_size(16), aligned (16)));
+
+template<int I>
+static v4ui t1(unsigned *dest_data)
+{
+  typedef unsigned v4ui_1 __attribute__ ((vector_size (16), aligned (4)));
+  return ((const v4ui_1*)dest_data)[0];
+}
+
+v4ui f(unsigned int *array)
+{
+    return t1<1>(array+7);
+}