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

--- Comment #4 from Matthias Kretz (Vir) <mkretz at gcc dot gnu.org> ---
Davis makes a good point: Do we consider

1. 'g++ -fcontracts -fcontract-evaluation-semantic=ignore', and
2. 'g++ -fcontracts -fcontract-evaluation-semantic=enforce'

the same implementation? If yes, then it is wrong to implement a contract check
in such a way that the optimizer can "see" it (and optimize according to what
it sees). In that case -fcontracts-conservative-ipa is not a workaround but
possibly a correct implementation of "unspecified whether the predicate is
evaluated".

However, I would hope we can do better:

1. When a function with contract checks is inlined, then the caller is allowed
to see the contract check and its side effects. However, not the next caller of
that function (unless it is actually inlined again). This seems like a hard
problem to solve.

2. -fno-contracts-conservative-ipa could potentially be renamed to
"-fcontracts-assume-given-evaluation-semantic" or something in that direction.
While it does the same thing, it is clearer in what the users opts in to.

FWIW, note that 'g++ -march=x86-64-v3' and 'g++ -march=x86-64-v4' are
effectively different implementations: an inline function with the same tokens
(i.e. no ODR violation) is translated to incompatible instructions so that a
call from x86-64-v3 TUs can fail.

Reply via email to