[cfe-dev] request for comments on patch: detecting integer undefined behaviors

Chris Lattner clattner at apple.com
Sat Sep 11 14:50:06 PDT 2010


On Sep 10, 2010, at 11:16 AM, John Regehr wrote:

> Attached is a very small Clang patch that augments -ftrapv to check for divide by zero, mod by zero, and INT_MIN % -1.  The behavior on failure is inherited from trapv.

Thanks!  I applied a slightly tweaked version of this in r113705.

The tweaks were to rename the function to EmitUndefinedBehaviorIntegerDivAndRemCheck, to make it clear that it only applied to integer div/rem.

I also changed this:

+    llvm::Value *Cond2 = Builder.CreateAnd(
+                                    Builder.CreateICmpEQ(Ops.LHS, IntMin),
+                                    Builder.CreateICmpEQ(Ops.RHS, NegOne), "and");

Because the order of evaluation of the calls isn't defined, so different compilers could emit the icmp's in different orders.

Finally, I changed isFloatingType() to isRealFloatingType(), because the code wasn't safe on _Complex floats.

Thanks again John,

-Chris 



More information about the cfe-dev mailing list