As documented in the manual, we do not support type punning that toggles
the scalar storage order, so this adds a warning for the case of unions.
gcc/c/
PR c/100653
* c-decl.c (finish_struct): Warn for a union containing an aggregate
field with a differing scalar storage order.
gcc/testsuite/
* gcc.dg/sso-13.c: New test.
= c_build_qualified_type (fmain_type, TYPE_QUALS (ftype));
}
}
+
+ if (TREE_CODE (t) == UNION_TYPE
+ && AGGREGATE_TYPE_P (TREE_TYPE (field))
+ && TYPE_REVERSE_STORAGE_ORDER (t)
+ != TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (field)))
+ warning_at (DECL_SOURCE_LOCATION (field), OPT_Wscalar_storage_order,
+ "type punning toggles scalar storage order");
}
/* Now we have the truly final field list.
--- /dev/null
+/* Test support of scalar_storage_order attribute */
+
+/* { dg-do compile } */
+
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+#define REV_ENDIANNESS __attribute__((scalar_storage_order("big-endian")))
+#else
+#define REV_ENDIANNESS __attribute__((scalar_storage_order("little-endian")))
+#endif
+
+typedef struct tIp6Addr
+{
+ unsigned int s6_addr32[4];
+} tIp6Addr;
+
+struct _tBeTimNetAddr
+{
+ unsigned char isIPv4;
+ union
+ {
+ unsigned int addr;
+ tIp6Addr addr6; /* { dg-warning "type punning toggles" } */
+ } REV_ENDIANNESS u;
+} REV_ENDIANNESS;