[LLVMdev] overflow check

Eli Friedman eli.friedman at gmail.com
Wed Jul 13 12:48:42 PDT 2011


On Wed, Jul 13, 2011 at 12:09 PM, Pranav Bhandarkar
<pranavb at codeaurora.org> wrote:
> Hi,
>
> I have three constants (B, C and V) and V = B + C. I want to find out if B +
> C wraps around. The way I'll do it is, assuming B and C are both positive,
> to check if V < B or C.
> For this I need the values of B, C and V. I tried using APInt as below.
> ***
> If (isa<Constant> (B) && isa<Constant> (C) && isa<Constant>(V)) {
>      ConstantInt *CV = dyn_cast<ConstantInt>(V);
>      ConstantInt *CB = dyn_cast<ConstantInt>(B);
>      ConstantInt *CC = dyn_cast<ConstantInt>(C);
>      if (CV && CB && CC) {
>        const APInt &VVal = CV->getValue();
>        const APInt &BVal = CB->getValue();
>        const APInt &CVal = CC->getValue();
> ******
>
> But isn't APInt considered to represent unsigned integers ? Is there another
> way of doing this ?

APInt's aren't inherently signed or unsigned; see
http://llvm.org/doxygen/classllvm_1_1APInt.html#amgrp54923b9793dae891d9489cc5947f263a
.

-Eli




More information about the llvm-dev mailing list