]> git.ipfire.org Git - thirdparty/gcc.git/commit
ada: Fix miscompilation at -O2 due to aliasing issue caused by -gnatVa
authorEric Botcazou <ebotcazou@adacore.com>
Wed, 1 Oct 2025 10:28:59 +0000 (12:28 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Tue, 28 Oct 2025 10:24:06 +0000 (11:24 +0100)
commitf6eb93dec5d355933cd0478db6bf43dfdb3aad06
treeb0b1e24f019b0db9876e2ed0137410e615399f8f
parent7ad3907689aed6a7937c3d82dc3e79fe8fc5b8cb
ada: Fix miscompilation at -O2 due to aliasing issue caused by -gnatVa

The problem is that the expanded code generated by -gnatVa (-gnatVc to be
precise) violates strict aliasing rules, because it contains a 'Reference
to an elementary component that is nonaliased ('Reference is equivalent to
a pointer for code generation purposes and the "aliased" keyword is trusted
for components whose type is elementary by code generators).

Remove_Side_Effects already knows that it must make a copy for elementary
types instead of taking 'Reference, but it is fooled by the private type
of the expression.  The fix is to still use the Etype to build new nodes,
but to use its Underlying_Type to select the strategy to do so.

gcc/ada/ChangeLog:

* exp_util.adb (Remove_Side_Effects): Use separately the Etype of
the expression to build new nodes and its Underlying_Type to drive
part of the processing.
gcc/ada/exp_util.adb