]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Do not apply scalar storage order to pointer fields
authorEric Botcazou <ebotcazou@adacore.com>
Fri, 7 May 2021 18:44:36 +0000 (20:44 +0200)
committerEric Botcazou <ebotcazou@adacore.com>
Fri, 7 May 2021 18:47:48 +0000 (20:47 +0200)
Pointer fields (and vector fields originally) were not really considered
when the scalar_storage_order attribute, so they are swapped as well.
As pointed out, this is problematic to describe in DWARF and probably
not very useful in any case, so this pulls them out.

gcc/
* doc/extend.texi (scalar_storage_order): Mention effect on pointer
and vector fields.
* tree.h (reverse_storage_order_for_component_p): Return false if
the type is a pointer.
gcc/c/
* c-typeck.c (build_unary_op) <ADDR_EXPR>: Do not issue an error
on the address of a pointer field in a record with reverse SSO.
gcc/testsuite/
* gcc.dg/sso-12.c: New test.

gcc/c/c-typeck.c
gcc/doc/extend.texi
gcc/testsuite/gcc.dg/sso-12.c [new file with mode: 0644]
gcc/tree.h

index fdc7bb6125c24c914285b02535cd2337a07e3269..5bdc673d03a8eb2c4ead56a7100fc185915cea8e 100644 (file)
@@ -4866,6 +4866,7 @@ build_unary_op (location_t location, enum tree_code code, tree xarg,
          if (TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (TREE_OPERAND (arg, 0))))
            {
              if (!AGGREGATE_TYPE_P (TREE_TYPE (arg))
+                 && !POINTER_TYPE_P (TREE_TYPE (arg))
                  && !VECTOR_TYPE_P (TREE_TYPE (arg)))
                {
                  error_at (location, "cannot take address of scalar with "
index c8caf36f29305de4eaff3e05d94638d3e9c2968a..fd9175d1b3bb2ab4987d2089cb289fddd4cad2ae 100644 (file)
@@ -8551,6 +8551,9 @@ or an array whose component is a @code{union} or a @code{struct}, and it is
 possible for these fields to have a different scalar storage order than the
 enclosing type.
 
+Note that neither pointer nor vector fields are considered scalar fields in
+this context, so the attribute has no effects on these fields.
+
 This attribute is supported only for targets that use a uniform default
 scalar storage order (fortunately, most of them), i.e.@: targets that store
 the scalars either all in big-endian or all in little-endian.
diff --git a/gcc/testsuite/gcc.dg/sso-12.c b/gcc/testsuite/gcc.dg/sso-12.c
new file mode 100644 (file)
index 0000000..3bed280
--- /dev/null
@@ -0,0 +1,27 @@
+/* Test scalar_storage_order attribute and pointer fields */
+
+/* { dg-do run } */
+/* { dg-options "-Wno-pedantic" } */
+
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+struct __attribute__((scalar_storage_order("big-endian"))) Rec
+{
+  int *p;
+};
+#else
+struct __attribute__((scalar_storage_order("little-endian"))) Rec
+{
+  int *p;
+};
+#endif
+
+int main (int argc)
+{
+  struct Rec r = { &argc };
+  int *p = &argc;
+
+  if (__builtin_memcmp (&r.p, &p, sizeof (int *)) != 0)
+    __builtin_abort ();
+
+  return 0;
+}
index 6d3cfc4c588e945f7cb75a69974bbef2f5e7ad3b..784452ca490e96cff0db9e94162952a736134214 100644 (file)
@@ -4989,7 +4989,9 @@ static inline bool
 reverse_storage_order_for_component_p (tree t)
 {
   /* The storage order only applies to scalar components.  */
-  if (AGGREGATE_TYPE_P (TREE_TYPE (t)) || VECTOR_TYPE_P (TREE_TYPE (t)))
+  if (AGGREGATE_TYPE_P (TREE_TYPE (t))
+      || POINTER_TYPE_P (TREE_TYPE (t))
+      || VECTOR_TYPE_P (TREE_TYPE (t)))
     return false;
 
   if (TREE_CODE (t) == REALPART_EXPR || TREE_CODE (t) == IMAGPART_EXPR)