From 6b9d6613897c48fee279754cb330320d011e05b4 Mon Sep 17 00:00:00 2001 From: Daniel Sanders Date: Fri, 21 Sep 2018 16:32:49 +0000 Subject: [PATCH] [tblgen] Fix undefined behaviour when assigning integers to large bits's This code: bits<96> X = 0; was triggering undefined behaviour since it iterates over bits 0..95 and tests them against the IntInit using 1LL << I. This patch resolves the undefined behaviour by continuing to treat the IntInit as a 64-bit value and simply causing all bit tests in excess of 64-bits to report false. As a result, bits<96> X = -1; will be equivalent to: bits<96> X; let X{0-63} = -1; let X{64-95} = 0; git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@342744 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/TableGen/Record.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/TableGen/Record.cpp b/lib/TableGen/Record.cpp index 43d178caef30..24251bc57f63 100644 --- a/lib/TableGen/Record.cpp +++ b/lib/TableGen/Record.cpp @@ -487,7 +487,7 @@ Init *IntInit::convertInitializerTo(RecTy *Ty) const { SmallVector NewBits(BRT->getNumBits()); for (unsigned i = 0; i != BRT->getNumBits(); ++i) - NewBits[i] = BitInit::get(Value & (1LL << i)); + NewBits[i] = BitInit::get(Value & ((i < 64) ? (1LL << i) : 0)); return BitsInit::get(NewBits); }