[PATCH] D74220: [TableGen] Fix spurious type error in bit assignment.
Simon Tatham via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 7 06:48:00 PST 2020
simon_tatham created this revision.
simon_tatham added reviewers: nhaehnle, hfinkel.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
The following example gives the error message "expected value of type
'bits<32>', got 'bit'" on the assignment.
class Instruction { bits<32> encoding; }
def foo: Instruction { let encoding{10} = !eq(0, 1); }
But there's nothing wrong with this code: 'bit' is a perfectly good
type for the RHS of an assignment to a //single bit// of an
instruction encoding.
The problem is that `ParseBodyItem` is accidentally type-checking the
RHS against the full type of the `encoding` field, without adjusting
it in the case where we're only assigning to a subset of the bits. The
fix is trivial.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D74220
Files:
llvm/lib/TableGen/TGParser.cpp
llvm/test/TableGen/BitsInit.td
Index: llvm/test/TableGen/BitsInit.td
===================================================================
--- llvm/test/TableGen/BitsInit.td
+++ llvm/test/TableGen/BitsInit.td
@@ -56,6 +56,10 @@
// Make sure we can initialise ints with bits<> values.
int J = H;
int K = { 0, 1 };
+
+ bits<2> L;
+ let L{0} = 1;
+ let L{1} = !eq(L{0}, 0);
}
// CHECK: def {{.*}} {
@@ -82,4 +86,5 @@
// CHECK: bits<16> I = { 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0 };
// CHECK: int J = 52275;
// CHECK: int K = 1;
+// CHECK: bits<2> L = { 0, 1 };
// CHECK: }
Index: llvm/lib/TableGen/TGParser.cpp
===================================================================
--- llvm/lib/TableGen/TGParser.cpp
+++ llvm/lib/TableGen/TGParser.cpp
@@ -2640,6 +2640,11 @@
return TokError("Value '" + FieldName->getValue() + "' unknown!");
RecTy *Type = Field->getType();
+ if (!BitList.empty() && isa<BitsRecTy>(Type)) {
+ // When assigning to a subset of a 'bits' object, expect the RHS to have
+ // the type of that subset instead of the type of the whole object.
+ Type = BitsRecTy::get(BitList.size());
+ }
Init *Val = ParseValue(CurRec, Type);
if (!Val) return true;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74220.243158.patch
Type: text/x-patch
Size: 1195 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200207/215e69de/attachment.bin>
More information about the llvm-commits
mailing list