Tighten up assertion checking
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4939 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/utils/TableGen/FileParser.y b/utils/TableGen/FileParser.y
index 38efb83..ff3ec40 100644
--- a/utils/TableGen/FileParser.y
+++ b/utils/TableGen/FileParser.y
@@ -89,14 +89,21 @@
BitsInit *NewVal = new BitsInit(CurVal->getNumBits());
- for (unsigned i = 0, e = CurVal->getNumBits(); i != e; ++i)
- NewVal->setBit(i, CurVal->getBit(i));
-
- // Loop over bits, assigning values as appopriate...
+ // Loop over bits, assigning values as appropriate...
for (unsigned i = 0, e = BitList->size(); i != e; ++i) {
unsigned Bit = (*BitList)[i];
+ if (NewVal->getBit(i)) {
+ err() << "Cannot set bit #" << i << " of value '" << ValName
+ << "' more than once!\n";
+ abort();
+ }
NewVal->setBit(Bit, BInit->getBit(i));
}
+
+ for (unsigned i = 0, e = CurVal->getNumBits(); i != e; ++i)
+ if (NewVal->getBit(i) == 0)
+ NewVal->setBit(i, CurVal->getBit(i));
+
V = NewVal;
}
diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp
index 5931cb8..d48d987 100644
--- a/utils/TableGen/Record.cpp
+++ b/utils/TableGen/Record.cpp
@@ -211,12 +211,14 @@
for (unsigned i = 0, e = Bits.size(); i != e; ++i) {
Init *B;
- New->setBit(i, getBit(i));
+ Init *CurBit = getBit(i);
+
do {
- B = New->getBit(i);
- New->setBit(i, B->resolveReferences(R));
- Changed |= B != New->getBit(i);
- } while (B != New->getBit(i));
+ B = CurBit;
+ CurBit = CurBit->resolveReferences(R);
+ Changed |= B != CurBit;
+ } while (B != CurBit);
+ New->setBit(i, CurBit);
}
if (Changed)
diff --git a/utils/TableGen/Record.h b/utils/TableGen/Record.h
index 8c55140..4f955b5 100644
--- a/utils/TableGen/Record.h
+++ b/utils/TableGen/Record.h
@@ -245,6 +245,7 @@
}
void setBit(unsigned Bit, Init *V) {
assert(Bit < Bits.size() && "Bit index out of range!");
+ assert(Bits[Bit] == 0 && "Bit already set!");
Bits[Bit] = V;
}