aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/sso-13.c
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2021-05-26 19:12:05 +0200
committerEric Botcazou <ebotcazou@adacore.com>2021-05-26 19:13:56 +0200
commit401bd4adcfda9965363b1ac3ba7e1580f15d6883 (patch)
treec71b1e857c1b29bbf42ae593ede1de9fa560e61a /gcc/testsuite/gcc.dg/sso-13.c
parent0e1fd432e9cd5a2a4703c9ef9cc61255ea22cc49 (diff)
downloadgcc-401bd4adcfda9965363b1ac3ba7e1580f15d6883.zip
gcc-401bd4adcfda9965363b1ac3ba7e1580f15d6883.tar.gz
gcc-401bd4adcfda9965363b1ac3ba7e1580f15d6883.tar.bz2
Warn on type punning that toggles scalar storage order
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.
Diffstat (limited to 'gcc/testsuite/gcc.dg/sso-13.c')
-rw-r--r--gcc/testsuite/gcc.dg/sso-13.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/sso-13.c b/gcc/testsuite/gcc.dg/sso-13.c
new file mode 100644
index 0000000..ddfde00
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/sso-13.c
@@ -0,0 +1,24 @@
+/* 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;