This is an archive of the discontinued LLVM Phabricator instance.

ADT: Fix that APSInt's string constructor claims it requires 5 bits to store a zero
ClosedPublic

Authored by teemperor on Jun 6 2020, 3:09 AM.

Details

Summary

When constructing an APSInt from a string, the constructor doesn't correctly
truncate the bit width of the result if the passed in string was "0" (or any alternative
way to express 0 like "-0" or "000"). Instead of 1 (which is the smallest allowed bit
width) it returns an APSInt with a bit width of 5.

The reason is that the constructor checks that it never truncates the result to the
invalid bit width of 0, so when it calculates that storing a "0" doesn't require any
bits it just keeps the original overestimated bit width (which happens to be 5).

This patch just sets the bit width of the result to 1 if the required bit width is 0.

Diff Detail

Event Timeline

teemperor created this revision.Jun 6 2020, 3:09 AM
teemperor updated this revision to Diff 269008.Jun 6 2020, 3:11 AM
  • Rename the test.
This revision is now accepted and ready to land.Jun 8 2020, 1:35 PM
This revision was automatically updated to reflect the committed changes.