diff --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp --- a/llvm/lib/TableGen/TGParser.cpp +++ b/llvm/lib/TableGen/TGParser.cpp @@ -2640,6 +2640,11 @@ return TokError("Value '" + FieldName->getValue() + "' unknown!"); RecTy *Type = Field->getType(); + if (!BitList.empty() && isa(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; diff --git a/llvm/test/TableGen/BitsInit.td b/llvm/test/TableGen/BitsInit.td --- a/llvm/test/TableGen/BitsInit.td +++ b/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: }