[Bug tree-optimization/119253] RISC-V GCC auto-vectorizes unaligned memory access even if mvector-strict-align is enabled
Dusan.Stojkovic@rt-rk.com
gcc-bugzilla@gcc.gnu.org
Thu Mar 13 09:54:06 GMT 2025
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119253
Dusan Stojkovic <Dusan.Stojkovic@rt-rk.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|INVALID |FIXED
--- Comment #2 from Dusan Stojkovic <Dusan.Stojkovic@rt-rk.com> ---
(In reply to Andrew Pinski from comment #1)
> >replicates the unaligned 32-bit
> >(uint32_t *)(flag_buf + (bit_pos >> 3))
>
>
> Yes because this is undefined code. You need to use either a type which has
> an alignment of 1 or use memcpy (without a cast to the pointer of an aligned
> type).
Looking at the compiler warnings, this could be something to consider:
* -Wall doesn't warn that this is undefined code;
* -Wextra doesn't warn that this is undefined code;
* -Wcast-align is the only case when this warning is written:
warning: cast increases required alignment of target type [-Wcast-align]
122 | (*(uint32_t *)(flag_buf + (bit_pos >> 3))) >> (bit_pos &
7);
But it's not enabled by default:
# gcc -Q --help=warnings | grep cast-align
-Wcast-align [disabled]
-Wcast-align=strict [disabled]
Maybe something to consider when compiling with -Wall -mstrict-align or
-mvector-strict-align is to have these warnings enabled.
More information about the Gcc-bugs
mailing list