diff mbox series

gcc.dg/pr94600-5.c .. -8.c: Align struct t0 explictly, as a type, PR middle-end/94600

Message ID 202008130316.07D3GoCh008782@ignucius.se.axis.com
State New
Headers show
Series gcc.dg/pr94600-5.c .. -8.c: Align struct t0 explictly, as a type, PR middle-end/94600 | expand

Commit Message

Hans-Peter Nilsson Aug. 13, 2020, 3:16 a.m. UTC
Committed as obvious.

The bitfield-struct t0 in gcc.dg/pr94600-1.c ..-4.c is assigned through
a pointer that is a (volatile-and-pointer-)cast literal, so gcc doesn't
need to be otherwise told that the address is aligned.  But, variants
pr94600-5.c ..-8.c are assigned through a "volatile t0 *", and rely on
the *type* being naturally aligned, or that the machine has
non-strict-alignment moves.

Unfortunately, systems exist (for some definitions of exist) where
such structs aren't always naturally aligned, for example if it
contains only (small) bitfields, even though the size is a naturally
accessible size.  Specifically, the mmix-knuth-mmixware port has only
*byte* alignment for this struct.  (If an int is added to the struct,
alignment is promoted.)  IOW, a prerequisite of the test is false: the
struct doesn't have the same alignment as an integer of the same size.
The effect is assignment in byte-size pieces, and the test fails.
(For a non-volatile assignment, memcpy is called.)  That's easily
fixable by defining the type as having a specific alignment.  This is
also closer to the type in the original code, and also as the first
variants aren't affected, no second thought or re-visit of pre-fixed
compiler is needed.  I don't plan to back-port this to gcc-10 branch
however.  I did sanity-check that the tests still pass on
ppc64le-linux.

gcc/testsuite:

	PR middle-end/94600
	* gcc.dg/pr94600-5.c, gcc.dg/pr94600-6.c, gcc.dg/pr94600-7.c,
	gcc.dg/pr94600-8.c: Align t0 to 4-byte boundary.
diff mbox series

Patch

--- gcc/gcc/testsuite/gcc.dg/pr94600-5.c.orig	Mon Jul 13 21:02:59 2020
+++ gcc/gcc/testsuite/gcc.dg/pr94600-5.c	Sun Aug  9 05:03:32 2020
@@ -9,7 +9,7 @@  typedef struct {
   unsigned int f1 : 11;
   unsigned int f2 : 10;
   unsigned int f3 : 7;
-} t0;
+} t0 __attribute__((__aligned__(4)));
 
 static t0 a0[] = {
  { .f0 = 7, .f1 = 99, .f3 = 1, },
--- gcc/gcc/testsuite/gcc.dg/pr94600-6.c.orig	Mon Jul 13 21:02:59 2020
+++ gcc/gcc/testsuite/gcc.dg/pr94600-6.c	Sun Aug  9 05:05:36 2020
@@ -9,7 +9,7 @@  typedef struct {
   unsigned int f1 : 11;
   unsigned int f2 : 10;
   unsigned int f3 : 7;
-} t0;
+} t0 __attribute__((__aligned__(4)));
 
 void
 bar(volatile t0 *b)
--- gcc/gcc/testsuite/gcc.dg/pr94600-7.c.orig	Mon Jul 13 21:02:59 2020
+++ gcc/gcc/testsuite/gcc.dg/pr94600-7.c	Sun Aug  9 05:05:47 2020
@@ -9,7 +9,7 @@  typedef struct {
   unsigned int f1 : 11;
   unsigned int f2 : 10;
   unsigned int f3 : 7;
-} t0;
+} t0 __attribute__((__aligned__(4)));
 
 static t0 a0[] = {
  { .f0 = 7, .f1 = 99, .f3 = 1, },
--- gcc/gcc/testsuite/gcc.dg/pr94600-8.c.orig	Mon Jul 13 21:02:59 2020
+++ gcc/gcc/testsuite/gcc.dg/pr94600-8.c	Sun Aug  9 05:05:54 2020
@@ -9,7 +9,7 @@  typedef struct {
   unsigned int f1 : 11;
   unsigned int f2 : 10;
   unsigned int f3 : 7;
-} t0;
+} t0 __attribute__((__aligned__(4)));
 
 void
 bar(volatile t0 *b)