On 3/5/20 2:51 AM, Jakub Jelinek wrote:
Hi!
As the testcases shows, the -Wconversion warning behaves quite differently
when -fsanitize=undefined vs. when not sanitizing, but in the end it is
not something specific to sanitizing, if a user uses
return static_cast<uc>(static_cast<uc>((d++, a) << 1U) | b) | c;
instead of
return static_cast<uc>(static_cast<uc>(a << 1U) | b) | c;
and thus there is some COMPOUND_EXPR involved, cp_build_binary_op behaves
significantly different, e.g. shorten_binary_op will have different result
(uc for the case without COMPOUND_EXPR, int with it), but it isn't limited
to that.
The following patch attempts to handle those the same, basically ignoring
everything but the ultimately last operand of COMPOUND_EXPR(s) and treating
the other COMPOUND_EXPR(s) operand(s) just as side-effects that need to be
evaluated first.
How about improving get_narrower to handle COMPOUND_EXPR? I'd think
that would do the trick without affecting evaluation order.
Jason