[cfe-dev] Integer overflow checking
Eli Friedman
eli.friedman at gmail.com
Sat May 16 13:25:53 PDT 2009
2009/5/16 Martin Doucha <next_ghost at quick.cz>:
> + if (CGF.getContext().getLangOptions().OverflowChecking &&
> ValTy->isIntegerType()) {
> + std::string e = isInc ? "Integer increment overflow" : "Integer
> decrement overflow";
> + unsigned IID = ValTy->isSignedIntegerType() ?
> + llvm::Intrinsic::sadd_with_overflow :
> llvm::Intrinsic::uadd_with_overflow;
> + PresumedLoc loc =
> CGF.getContext().getSourceManager().getPresumedLoc(E->getOperatorLoc());
> + BinOpInfo Ops;
> + Ops.Ty = ValTy;
> + Ops.LHS = InVal;
> + Ops.RHS = NextVal;
> + NextVal = EmitOverflowInst(IID, e, loc, Ops);
> + } else {
> + NextVal = Builder.CreateAdd(InVal, NextVal, isInc ? "inc" : "dec");
> + }
> }
This is wrong: one, unsigned "overflow" is well-defined, and two,
CodeGen takes some shortcuts with inc/dec, so this will incorrectly
conclude that "short x = 0x7FFF; ++x;" overflows.
-Eli
More information about the cfe-dev
mailing list