[llvm] r347148 - tighten up a couple of assertions. hitting the BitPosition == BitWidth case that was previously not caught resulted in nasty corruption of APInts that (on my system at least) could not be detected using UBSan, ASan, or Valgrind. this patch does not cause any extra failures in a check-all nor does it interfere with bootstrapping. David Blaikie informally approved this change.

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 18 02:58:35 PST 2018


On Sun, Nov 18, 2018 at 4:54 AM John Regehr via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
>
> Author: regehr
> Date: Sat Nov 17 17:51:43 2018
> New Revision: 347148
>
> URL: http://llvm.org/viewvc/llvm-project?rev=347148&view=rev
> Log:
> tighten up a couple of assertions. hitting the BitPosition == BitWidth case that was previously not caught resulted in nasty corruption of APInts that (on my system at least) could not be detected using UBSan, ASan, or Valgrind. this patch does not cause any extra failures in a check-all nor does it interfere with bootstrapping. David Blaikie informally approved this change.

Please keep the first line of the commit message less than 80 symbols,
and separate the rest (and linewrap it!) with a newline.

> Modified:
>     llvm/trunk/include/llvm/ADT/APInt.h
>
> Modified: llvm/trunk/include/llvm/ADT/APInt.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APInt.h?rev=347148&r1=347147&r2=347148&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/ADT/APInt.h (original)
> +++ llvm/trunk/include/llvm/ADT/APInt.h Sat Nov 17 17:51:43 2018
> @@ -1395,7 +1395,7 @@ public:
>    ///
>    /// Set the given bit to 1 whose position is given as "bitPosition".
>    void setBit(unsigned BitPosition) {
> -    assert(BitPosition <= BitWidth && "BitPosition out of range");
> +    assert(BitPosition < BitWidth && "BitPosition out of range");
>      WordType Mask = maskBit(BitPosition);
>      if (isSingleWord())
>        U.VAL |= Mask;
> @@ -1454,7 +1454,7 @@ public:
>    ///
>    /// Set the given bit to 0 whose position is given as "bitPosition".
>    void clearBit(unsigned BitPosition) {
> -    assert(BitPosition <= BitWidth && "BitPosition out of range");
> +    assert(BitPosition < BitWidth && "BitPosition out of range");
>      WordType Mask = ~maskBit(BitPosition);
>      if (isSingleWord())
>        U.VAL &= Mask;
Sounds like something testable with an unit-test? (googletest EXPECT_DEATH)

> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list