https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111875

--- Comment #1 from Filip Kastl <fkastl at suse dot cz> ---
I found out that this is caused by the copy_prop pass. With -Og, an instance of
copy_prop runs after the fold_builtins pass but before the sanopt pass. The
fold_builtins pass changes the statement p_2 = __builtin_assume_aligned(p_1, 4)
to p_2 = p_1; and changes the alignment of p_2 to 32 bits. However the
alignment of p_1 remains 8 bits so when copy_prop propagates all occurences of
p_2 to instead be occurences of p_1, the information about alignment is lost.
When the sanopt pass runs, it decides that casting p to (int *) possibly
creates UB.

I see a few possible solutions:
- Stop copy prop from propagating through assignments where the alignments
differ
- Modify copy prop to use the alignment information of the lhs ssa name when
propagating through similar assignment statements
- Modify fold_builtins to copy propagate in similar cases
- Modify fold_builtins to also set alignment of the rhs ssa name when removing
__builtin_assume_aligned in similar cases

Reply via email to