[PATCH] D44476: TableGen: Explicitly forbid self-references to field members
Phabricator via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 19 07:17:21 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL327850: TableGen: Explicitly forbid self-references to field members (authored by nha, committed by ).
Repository:
rL LLVM
https://reviews.llvm.org/D44476
Files:
llvm/trunk/include/llvm/TableGen/Record.h
llvm/trunk/lib/TableGen/Record.cpp
llvm/trunk/lib/TableGen/TGParser.cpp
llvm/trunk/test/TableGen/self-reference-recursion.td
Index: llvm/trunk/lib/TableGen/Record.cpp
===================================================================
--- llvm/trunk/lib/TableGen/Record.cpp
+++ llvm/trunk/lib/TableGen/Record.cpp
@@ -1684,13 +1684,19 @@
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;
}
Index: llvm/trunk/lib/TableGen/TGParser.cpp
===================================================================
--- llvm/trunk/lib/TableGen/TGParser.cpp
+++ llvm/trunk/lib/TableGen/TGParser.cpp
@@ -1943,7 +1943,7 @@
Result->getAsString() + "'");
return nullptr;
}
- Result = FieldInit::get(Result, FieldName)->Fold();
+ Result = FieldInit::get(Result, FieldName)->Fold(CurRec);
Lex.Lex(); // eat field name
break;
}
Index: llvm/trunk/include/llvm/TableGen/Record.h
===================================================================
--- llvm/trunk/include/llvm/TableGen/Record.h
+++ llvm/trunk/include/llvm/TableGen/Record.h
@@ -1200,7 +1200,7 @@
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();
Index: llvm/trunk/test/TableGen/self-reference-recursion.td
===================================================================
--- llvm/trunk/test/TableGen/self-reference-recursion.td
+++ llvm/trunk/test/TableGen/self-reference-recursion.td
@@ -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">;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44476.138917.patch
Type: text/x-patch
Size: 2622 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180319/c8e30f32/attachment.bin>
More information about the llvm-commits
mailing list