This is an archive of the discontinued LLVM Phabricator instance.

[APInt] Fix getBitsNeeded for INT_MIN values
ClosedPublic

Authored by Quolyk on Jun 23 2019, 2:42 AM.

Details

Summary

This patch fixes behaviour of APInt::getBitsNeeded for INT_MIN 10 bits values.

Diff Detail

Event Timeline

Quolyk created this revision.Jun 23 2019, 2:42 AM
grandinj added inline comments.
lib/Support/APInt.cpp
488

this seems inefficient? we're calling logbase2 and exactlogbase2? Perhaps just call isPowerOf2() directly since exactlogbase2 is

int32_t exactLogBase2() const {

  if (!isPowerOf2())
    return -1;
  return logBase2();
}

?

Just a suggestion

RKSimon added inline comments.Jun 27 2019, 9:43 AM
unittests/ADT/APIntTest.cpp
1269

Please can you add a few other INT_MIN cases - regular and irregular sizes (e.g. i1, i23, i32, i64)

RKSimon accepted this revision.Jun 28 2019, 5:35 AM

LGTM - thanks!

This revision is now accepted and ready to land.Jun 28 2019, 5:35 AM
This revision was automatically updated to reflect the committed changes.