summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2011-06-03 08:25:39 +0000
committerNick Lewycky <nicholas@mxc.ca>2011-06-03 08:25:39 +0000
commitb2afe8759dbbed1d74da361ef0db1a4aaafefdb3 (patch)
treeae1099a6edc97cc0374864647f135c260b209ca2 /utils
parent444f297a782047fbe6255a3543bc3ccd025c0691 (diff)
downloadllvm-b2afe8759dbbed1d74da361ef0db1a4aaafefdb3.tar.gz
llvm-b2afe8759dbbed1d74da361ef0db1a4aaafefdb3.tar.bz2
llvm-b2afe8759dbbed1d74da361ef0db1a4aaafefdb3.tar.xz
Rework the logic to not rely on undefined behaviour (1LL << 64). Also simplify.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@132537 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils')
-rw-r--r--utils/TableGen/Record.cpp11
1 files changed, 3 insertions, 8 deletions
diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp
index c427b761d8..8ac8cd9716 100644
--- a/utils/TableGen/Record.cpp
+++ b/utils/TableGen/Record.cpp
@@ -68,14 +68,9 @@ Init *BitsRecTy::convertValue(BitInit *UI) {
/// canFitInBitfield - Return true if the number of bits is large enough to hold
/// the integer value.
static bool canFitInBitfield(int64_t Value, unsigned NumBits) {
- if (Value >= 0) {
- if (Value & ~((1LL << NumBits) - 1))
- return false;
- } else if ((Value >> NumBits) != -1 || (Value & (1LL << (NumBits-1))) == 0) {
- return false;
- }
-
- return true;
+ // For example, with NumBits == 4, we permit Values from [-7 .. 15].
+ return (NumBits >= sizeof(Value) * 8) ||
+ (Value >> NumBits == 0) || (Value >> (NumBits-1) == -1);
}
/// convertValue from Int initializer to bits type: Split the integer up into the