[LLVMdev] Question about ExprConstant optimization of IR stage
Tim Northover
t.p.northover at gmail.com
Thu Nov 28 06:02:51 PST 2013
Hi Haishan,
> int foo(int j) {
> return ++j > 0;
> }
> int main() {
> if (foo(((~0U)>>1)))
> abort();
> exit(0)
> }
This test contains undefined behaviour, and you can never rely on the
compiler doing anything predictable with that. Specifically, the
result of casting (~0U) >> 1 to an int is almost certainly INT_MAX and
when foo increments it integer overflow occurs, which is undefined.
Cheers.
Tim.
More information about the llvm-dev
mailing list