This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/20982] alignment attribute ignired for vector pointers types
- From: "manu at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 16 Nov 2007 19:32:54 -0000
- Subject: [Bug middle-end/20982] alignment attribute ignired for vector pointers types
- References: <bug-20982-10424@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #2 from manu at gcc dot gnu dot org 2007-11-16 19:32 -------
(In reply to comment #1)
> aligned can never decrease the required alignment.
>
Can we detect this and emit a diagnostic? We do it for declarations already but
not for types. I tried the following patch as a wild guess but it generates
regressions in gcc.dg/compat/struct-layout-1 and similar.
Index: gcc/testsuite/gcc.dg/pr20982.c
===================================================================
--- gcc/testsuite/gcc.dg/pr20982.c (revision 0)
+++ gcc/testsuite/gcc.dg/pr20982.c (revision 0)
@@ -0,0 +1,11 @@
+/* PR 20982 alignment attribute ignored for vector pointers types */
+/* { dg-do compile } */
+/* { dg-options "-msse " } */
+typedef float v4sf __attribute__ ((mode(V4SF),aligned(8)));
+/* { dg-warning "specifying vector types with __attribute__ ..mode.. is
deprecated" } "" { target *-*-* } 4 }*/
+/* { dg-warning " use .* instead" "" { target *-*-* } 4 } */
+/* { dg-error "alignment for .* must be at least" "" { target *-*-* } 4 } */
+
+v4sf foo(v4sf *p, v4sf *q) {
+ return *p + *q;
+}
Index: gcc/c-common.c
===================================================================
--- gcc/c-common.c (revision 130174)
+++ gcc/c-common.c (working copy)
@@ -5438,23 +5438,38 @@
}
else if (is_type)
{
- /* If we have a TYPE_DECL, then copy the type, so that we
- don't accidentally modify a builtin type. See pushdecl. */
- if (decl && TREE_TYPE (decl) != error_mark_node
- && DECL_ORIGINAL_TYPE (decl) == NULL_TREE)
- {
- tree tt = TREE_TYPE (decl);
- *type = build_variant_type_copy (*type);
- DECL_ORIGINAL_TYPE (decl) = tt;
- TYPE_NAME (*type) = decl;
- TREE_USED (*type) = TREE_USED (decl);
- TREE_TYPE (decl) = *type;
- }
- else if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
- *type = build_variant_type_copy (*type);
-
- TYPE_ALIGN (*type) = (1 << i) * BITS_PER_UNIT;
- TYPE_USER_ALIGN (*type) = 1;
+ if (TYPE_ALIGN (*type) > (unsigned) (1 << i) * BITS_PER_UNIT)
+ {
+ if (TYPE_USER_ALIGN (*type))
+ error ("alignment for %qT was previously specified as %d "
+ "and may not be decreased", *type,
+ TYPE_ALIGN (*type) / BITS_PER_UNIT);
+ else
+ error ("alignment for %qT must be at least %d", *type,
+ TYPE_ALIGN (*type) / BITS_PER_UNIT);
+ *no_add_attrs = true;
+ }
+ else
+ {
+ /* If we have a TYPE_DECL, then copy the type, so that we
+ don't accidentally modify a builtin type. See pushdecl. */
+ if (decl && TREE_TYPE (decl) != error_mark_node
+ && DECL_ORIGINAL_TYPE (decl) == NULL_TREE)
+ {
+ tree tt = TREE_TYPE (decl);
+ *type = build_variant_type_copy (*type);
+ DECL_ORIGINAL_TYPE (decl) = tt;
+ TYPE_NAME (*type) = decl;
+ TREE_USED (*type) = TREE_USED (decl);
+ TREE_TYPE (decl) = *type;
+ }
+ else if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
+ *type = build_variant_type_copy (*type);
+
+
+ TYPE_ALIGN (*type) = (1 << i) * BITS_PER_UNIT;
+ TYPE_USER_ALIGN (*type) = 1;
+ }
}
else if (! VAR_OR_FUNCTION_DECL_P (decl)
&& TREE_CODE (decl) != FIELD_DECL)
--
manu at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |manu at gcc dot gnu dot org
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2007-11-16 19:32:54
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20982