[llvm] r342744 - [tblgen] Fix undefined behaviour when assigning integers to large bits<n>'s
Daniel Sanders via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 21 09:32:49 PDT 2018
Author: dsanders
Date: Fri Sep 21 09:32:49 2018
New Revision: 342744
URL: http://llvm.org/viewvc/llvm-project?rev=342744&view=rev
Log:
[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;
Modified:
llvm/trunk/lib/TableGen/Record.cpp
Modified: llvm/trunk/lib/TableGen/Record.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/Record.cpp?rev=342744&r1=342743&r2=342744&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/Record.cpp (original)
+++ llvm/trunk/lib/TableGen/Record.cpp Fri Sep 21 09:32:49 2018
@@ -487,7 +487,7 @@ Init *IntInit::convertInitializerTo(RecT
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);
}
More information about the llvm-commits
mailing list