From 6e9457fc4da9d77ec671ca594144aec8b9753321 Mon Sep 17 00:00:00 2001 From: Guillaume Chatelet Date: Mon, 6 Jul 2020 08:47:58 +0000 Subject: [PATCH] Fix off by one error in Bitfields Differential Revision: https://reviews.llvm.org/D83192 --- include/llvm/ADT/Bitfields.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/llvm/ADT/Bitfields.h b/include/llvm/ADT/Bitfields.h index 2e38cca673e..68b1549a0ac 100644 --- a/include/llvm/ADT/Bitfields.h +++ b/include/llvm/ADT/Bitfields.h @@ -227,7 +227,7 @@ struct Bitfield { static constexpr unsigned Shift = Offset; static constexpr unsigned Bits = Size; static constexpr unsigned FirstBit = Offset; - static constexpr unsigned LastBit = Shift + Bits; + static constexpr unsigned LastBit = Shift + Bits - 1; private: template friend struct bitfields_details::Impl; @@ -273,7 +273,7 @@ struct Bitfield { /// Returns whether the two bitfields share common bits. template static constexpr bool isOverlapping() { - return A::LastBit > B::FirstBit && B::LastBit > A::FirstBit; + return A::LastBit >= B::FirstBit && B::LastBit >= A::FirstBit; } };