Rework the logic to not rely on undefined behaviour (1LL << 64). Also simplify.
llvm-svn: 132537
This commit is contained in:
parent
21cd5db7bd
commit
79286bf251
|
@ -68,14 +68,9 @@ Init *BitsRecTy::convertValue(BitInit *UI) {
|
||||||
/// canFitInBitfield - Return true if the number of bits is large enough to hold
|
/// canFitInBitfield - Return true if the number of bits is large enough to hold
|
||||||
/// the integer value.
|
/// the integer value.
|
||||||
static bool canFitInBitfield(int64_t Value, unsigned NumBits) {
|
static bool canFitInBitfield(int64_t Value, unsigned NumBits) {
|
||||||
if (Value >= 0) {
|
// For example, with NumBits == 4, we permit Values from [-7 .. 15].
|
||||||
if (Value & ~((1LL << NumBits) - 1))
|
return (NumBits >= sizeof(Value) * 8) ||
|
||||||
return false;
|
(Value >> NumBits == 0) || (Value >> (NumBits-1) == -1);
|
||||||
} else if ((Value >> NumBits) != -1 || (Value & (1LL << (NumBits-1))) == 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// convertValue from Int initializer to bits type: Split the integer up into the
|
/// convertValue from Int initializer to bits type: Split the integer up into the
|
||||||
|
|
Loading…
Reference in New Issue