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

--- Comment #7 from Steven Pigeon <steven.p.pigeon at gmail dot com> ---
(In reply to Andrew Pinski from comment #6)
> Once undefined behavior happens all bets are off of any behavior of the
> program. 
> 
> In this case the function is in lined and the optimizers see i cannot
> overflow the multiply so it removes the loop check.

I do understand that this is what happens (the code is fixed by promoting
int32_t t=x to int64_t t=x) but the undefined behavior affects a variable (and
its associated comparison) that should not be affected by it. It's as if this
program

int32_t f(int16_t x) { return x*65793; }

for (int i=-32768; i<32768; i++)
 std::cout << f(i) << std::endl;

would just never stop. Would that be expected?

Reply via email to