[Bug c/79065] ARM generates ldm/stm on packed structs with aligned members

2017-01-11 Thread vielster at zee dot aero
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79065

--- Comment #1 from Brian Viele  ---
gcc version 5.4.1 20160609 (release) [ARM/embedded-5-branch revision 237715]
(GCC) 

System: Linux xxx 4.4.0-47-generic #68~14.04.1-Ubuntu SMP Wed Oct 26 19:42:11
UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

[Bug c/79065] New: ARM generates ldm/stm on packed structs with aligned members

2017-01-11 Thread vielster at zee dot aero
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79065

Bug ID: 79065
   Summary: ARM generates ldm/stm on packed structs with aligned
members
   Product: gcc
   Version: 5.4.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: vielster at zee dot aero
  Target Milestone: ---

LDM/STM do not support unaligned access, so packed structs should not be
accessed in this way. If internal members of the struct are aligned to pad for
inter-platform compatibility (in this case, variable enum size), GCC generates
LDM/STM and can cause unaligned access faults.

Below is the code and the assembly generated with arm-none-eabi-gcc -O1

#include 
typedef struct __attribute__((__packed__))
{
  uint32_t a;
  uint8_t b __attribute__((aligned(4)));
  uint8_t c; 
}foo_t;

void struct_copy(foo_t *p_dest, foo_t *p_src)
{
  *p_src = *p_dest;
}

struct_copy(foo_t*, foo_t*):
mov r3, r1
ldmia   r0, {r0, r1}
stmia   r3, {r0, r1}
bx  lr