https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106818
--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to baoshan from comment #5)
> Per Andrew's request:
>
> For GCC built for RISC-V,
> With the following code:
> struct sss_t {
> int i;
> int j;
> } sss;
> extern char array[sizeof(struct sss_t )];
> void foo()
> {
> struct sss_t *p = (struct sss_t *)array;
> p->i = 10;
Note we should know here that p->i = 10 accesses memory aligned
according to the alignment of an 'int' (unless riscv is packed by
default and doesn't have 'sss' aligned to an 'int').
That's because C guarantees this.
We lose this fact because get_object_alignment_2 "knows better", aka
in some places GCC tries to work like a DWIM compiler, saving people
from mistakes. Here get_inner_reference sees we access 'array' and
adjusts alignment according to its alignment, ignoring what the language
standard guarantees.