I am using the TI ARM compiler v5.0.4, with the TMS570 microcontroller. I've encountered a compiler bug when assigning unions. Attached is a program with different tests.
Assignments to unions are implemented using the STMEA instruction and reading unions using the LDMFD instruction. When the union is not word-aligned, this leads to data abort exceptions. See the example program, test cases 1 and 2.
As a workaround, one can use the memcpy method, though that is optimized to STMEA and LDMFD instructions when passed union pointers or void pointers. To force a call to memcpy, one can cast the source to a uint8_t*. See test case 3.
This is not a problem for structs, as there the assignment seem to always be translated to a memcpy call. See test case 4.
When embedding a union in a struct the generated code behave correctly, as the union is word-aligned in the struct. When packing the struct, memcpy is used to copy the data (also correct). See test case 5.