summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorNicolai Haehnle <nhaehnle@gmail.com>2018-03-19 14:14:28 +0000
committerNicolai Haehnle <nhaehnle@gmail.com>2018-03-19 14:14:28 +0000
commit2ad19016c086d1915a8e96e2a63ca291719300ee (patch)
treed448ca5aecd87d6033555c8656b27754736509e0 /llvm/lib
parent4186cc7c08b2c1cdd7f7a583fa728e065b5be033 (diff)
downloadbcm5719-llvm-2ad19016c086d1915a8e96e2a63ca291719300ee.tar.gz
bcm5719-llvm-2ad19016c086d1915a8e96e2a63ca291719300ee.zip
TableGen: Explicitly forbid self-references to field members
Summary: Otherwise, patterns like in the test case produce cryptic error messages about fields being resolved incompletely. Change-Id: I713c0191f00fe140ad698675803ab1f8823dc5bd Reviewers: arsenm, craig.topper, tra, MartinO Subscribers: wdng, llvm-commits Differential Revision: https://reviews.llvm.org/D44476 llvm-svn: 327850
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/TableGen/Record.cpp12
-rw-r--r--llvm/lib/TableGen/TGParser.cpp2
2 files changed, 10 insertions, 4 deletions
diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp
index 333f45b7be9..866cda3152f 100644
--- a/llvm/lib/TableGen/Record.cpp
+++ b/llvm/lib/TableGen/Record.cpp
@@ -1684,13 +1684,19 @@ Init *FieldInit::getBit(unsigned Bit) const {
Init *FieldInit::resolveReferences(Resolver &R) const {
Init *NewRec = Rec->resolveReferences(R);
if (NewRec != Rec)
- return FieldInit::get(NewRec, FieldName)->Fold();
+ return FieldInit::get(NewRec, FieldName)->Fold(R.getCurrentRecord());
return const_cast<FieldInit *>(this);
}
-Init *FieldInit::Fold() const {
+Init *FieldInit::Fold(Record *CurRec) const {
if (DefInit *DI = dyn_cast<DefInit>(Rec)) {
- Init *FieldVal = DI->getDef()->getValue(FieldName)->getValue();
+ Record *Def = DI->getDef();
+ if (Def == CurRec)
+ PrintFatalError(CurRec->getLoc(),
+ Twine("Attempting to access field '") +
+ FieldName->getAsUnquotedString() + "' of '" +
+ Rec->getAsString() + "' is a forbidden self-reference");
+ Init *FieldVal = Def->getValue(FieldName)->getValue();
if (FieldVal->isComplete())
return FieldVal;
}
diff --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp
index 0c92cf74965..0eb75424db5 100644
--- a/llvm/lib/TableGen/TGParser.cpp
+++ b/llvm/lib/TableGen/TGParser.cpp
@@ -1943,7 +1943,7 @@ Init *TGParser::ParseValue(Record *CurRec, RecTy *ItemType, IDParseMode Mode) {
Result->getAsString() + "'");
return nullptr;
}
- Result = FieldInit::get(Result, FieldName)->Fold();
+ Result = FieldInit::get(Result, FieldName)->Fold(CurRec);
Lex.Lex(); // eat field name
break;
}
OpenPOWER on IntegriCloud