[LLVMdev] Question about ExprConstant optimization of IR stage

Tim Northover t.p.northover at gmail.com
Fri Nov 29 05:35:51 PST 2013


Hi Haishan

> But, in fact, the content of this test is the same to gcc\testsuite\gcc.c-torture\execute\920612-1.c.
> gcc can handle it correctly.

It looks like[1] GCC handles it by compiling the test with the flag
"-fwrapv" which tells the compiler to override the normal language
rules and treat integer overflow as defined and consistent with a
2s-complement representation.

Clang also supports this option, though personally I'd strongly
discourage it except for unmaintained and unmaintainable legacy code.

> That to say, for this test, clang with optlevel O2 execution result is
> different from O0. Is it reasonable?

Yes. It's one of the perils of undefined behaviour.

Cheers.

Tim.

[1] https://github.com/mirrors/gcc/blob/master/gcc/testsuite/gcc.c-torture/execute/920612-1.x



More information about the llvm-dev mailing list