[LLVMdev] APInt::sdivrem error?

Eli Friedman eli.friedman at gmail.com
Mon May 21 11:39:49 PDT 2012


On Mon, May 21, 2012 at 11:27 AM, Preston Briggs
<preston.briggs at gmail.com> wrote:
> OK, the code for sdivrem in APInt.h is wrong.
> Here's what's written:
>
>  static void sdivrem(const APInt &LHS, const APInt &RHS,
>                      APInt &Quotient, APInt &Remainder) {
>    if (LHS.isNegative()) {
>      if (RHS.isNegative())
>        APInt::udivrem(-LHS, -RHS, Quotient, Remainder);
>      else
>        APInt::udivrem(-LHS, RHS, Quotient, Remainder);
>      Quotient = -Quotient;
>      Remainder = -Remainder;
>    } else if (RHS.isNegative()) {
>      APInt::udivrem(LHS, -RHS, Quotient, Remainder);
>      Quotient = -Quotient;
>    } else {
>      APInt::udivrem(LHS, RHS, Quotient, Remainder);
>    }
>  }
>
>
> Here's what it should be:
>
>  static void sdivrem(const APInt &LHS, const APInt &RHS,
>                      APInt &Quotient, APInt &Remainder) {
>    if (LHS.isNegative()) {
>      if (RHS.isNegative())
>        APInt::udivrem(-LHS, -RHS, Quotient, Remainder);
>      else {
>        APInt::udivrem(-LHS, RHS, Quotient, Remainder);
>        Quotient = -Quotient;
>        Remainder = -Remainder;
>      }
>    } else if (RHS.isNegative()) {
>      APInt::udivrem(LHS, -RHS, Quotient, Remainder);
>      Quotient = -Quotient;
>    } else {
>      APInt::udivrem(LHS, RHS, Quotient, Remainder);
>    }
>  }
>
>
> What should I do to submit the correction?

Send a patch to llvm-commits, preferably including a testcase in
unittests/ADT/APIntTest.cpp .  See
http://llvm.org/docs/DeveloperPolicy.html#patches .

-Eli




More information about the llvm-dev mailing list