1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

[tblgen] Fix undefined behaviour when assigning integers to large bits<n>'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;

llvm-svn: 342744
This commit is contained in:
Daniel Sanders 2018-09-21 16:32:49 +00:00
parent 75615ce56c
commit fc637bb564

View File

@ -487,7 +487,7 @@ Init *IntInit::convertInitializerTo(RecTy *Ty) const {
SmallVector<Init *, 16> 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);
}