mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
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
This commit is contained in:
parent
a64a4772e8
commit
cd1f0648bf
@ -1200,7 +1200,7 @@ public:
|
||||
Init *getBit(unsigned Bit) const override;
|
||||
|
||||
Init *resolveReferences(Resolver &R) const override;
|
||||
Init *Fold() const;
|
||||
Init *Fold(Record *CurRec) const;
|
||||
|
||||
std::string getAsString() const override {
|
||||
return Rec->getAsString() + "." + FieldName->getValue().str();
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
9
test/TableGen/self-reference-recursion.td
Normal file
9
test/TableGen/self-reference-recursion.td
Normal file
@ -0,0 +1,9 @@
|
||||
// RUN: not llvm-tblgen %s 2>&1 | FileCheck %s
|
||||
// XFAIL: vg_leak
|
||||
|
||||
class A<string self> {
|
||||
int x = !cast<A>(self).x;
|
||||
}
|
||||
|
||||
// CHECK: error: Attempting to access field 'x' of 'A0' is a forbidden self-reference
|
||||
def A0 : A<"A0">;
|
Loading…
x
Reference in New Issue
Block a user