[llvm] be50657 - [TableGen] Resolve concrete but not complete field access initializers
Daniel Sanders via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 13 15:15:27 PDT 2021
Author: Daniel Sanders
Date: 2021-04-13T15:14:56-07:00
New Revision: be50657c6ac534215b2cef562e2a29197259ec85
URL: https://github.com/llvm/llvm-project/commit/be50657c6ac534215b2cef562e2a29197259ec85
DIFF: https://github.com/llvm/llvm-project/commit/be50657c6ac534215b2cef562e2a29197259ec85.diff
LOG: [TableGen] Resolve concrete but not complete field access initializers
This fixes the resolution of Rec10.Zero in ListSlices.td.
As part of this, correct the definition of complete for ListInit such that
it's complete iff all the elements in the list are complete rather than
always being complete regardless of the elements. This is the reason
Rec10.TwoFive from ListSlices.td previously resolved despite being
incomplete like Rec10.Zero was
Depends on D100247
Reviewed By: Paul-C-Anagnostopoulos
Differential Revision: https://reviews.llvm.org/D100253
Added:
Modified:
llvm/include/llvm/TableGen/Record.h
llvm/lib/TableGen/Record.cpp
llvm/test/TableGen/ListSlices.td
llvm/test/TableGen/field-access-initializers.td
Removed:
################################################################################
diff --git a/llvm/include/llvm/TableGen/Record.h b/llvm/include/llvm/TableGen/Record.h
index 9432de6738613..177679e317220 100644
--- a/llvm/include/llvm/TableGen/Record.h
+++ b/llvm/include/llvm/TableGen/Record.h
@@ -708,6 +708,7 @@ class ListInit final : public TypedInit, public FoldingSetNode,
///
Init *resolveReferences(Resolver &R) const override;
+ bool isComplete() const override;
bool isConcrete() const override;
std::string getAsString() const override;
diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp
index 92b583da9296c..1c36b64aee1ed 100644
--- a/llvm/lib/TableGen/Record.cpp
+++ b/llvm/lib/TableGen/Record.cpp
@@ -655,6 +655,14 @@ Init *ListInit::resolveReferences(Resolver &R) const {
return const_cast<ListInit *>(this);
}
+bool ListInit::isComplete() const {
+ for (Init *Element : *this) {
+ if (!Element->isComplete())
+ return false;
+ }
+ return true;
+}
+
bool ListInit::isConcrete() const {
for (Init *Element : *this) {
if (!Element->isConcrete())
@@ -1924,7 +1932,7 @@ Init *FieldInit::Fold(Record *CurRec) const {
FieldName->getAsUnquotedString() + "' of '" +
Rec->getAsString() + "' is a forbidden self-reference");
Init *FieldVal = Def->getValue(FieldName)->getValue();
- if (FieldVal->isComplete())
+ if (FieldVal->isConcrete())
return FieldVal;
}
return const_cast<FieldInit *>(this);
diff --git a/llvm/test/TableGen/ListSlices.td b/llvm/test/TableGen/ListSlices.td
index ef9fd534b6097..9e80fb215f885 100644
--- a/llvm/test/TableGen/ListSlices.td
+++ b/llvm/test/TableGen/ListSlices.td
@@ -111,8 +111,11 @@ def Rec08 {
// CHECK: def Rec09
// CHECK: int Zero = ?;
// CHECK: list<int> TwoFive = [2, 3, ?, 5];
-// CHECK: def Rec10
-// CHECK: list<int> TwoFive = [2, 3, ?, 5];
+// We need CHECK-NEXT for these because otherwise it will match anonymous defs
+// that appear later.
+// CHECK: def Rec10 {
+// CHECK-NEXT: int Zero = ?;
+// CHECK-NEXT: list<int> TwoFive = [2, 3, ?, 5];
def Rec09 : Class1<[?, ?, 2, 3, ?, 5, ?]>;
@@ -120,6 +123,3 @@ def Rec10 {
int Zero = Class1<[?, ?, 2, 3, ?, 5, ?]>.Zero;
list<int> TwoFive = Class1<[?, ?, 2, 3, ?, 5, ?]>.TwoFive;
}
-
-// TO-DO: Notice that the first field in Rec10 is not checked.
-// It is not fully resolved for reasons that need to be investigated.
diff --git a/llvm/test/TableGen/field-access-initializers.td b/llvm/test/TableGen/field-access-initializers.td
index 5a25e2901aeea..ca25d067a1689 100644
--- a/llvm/test/TableGen/field-access-initializers.td
+++ b/llvm/test/TableGen/field-access-initializers.td
@@ -1,6 +1,10 @@
// RUN: llvm-tblgen %s | FileCheck %s
// XFAIL: vg_leak
+// CHECK: class B<A B:impl = ?> {
+// CHECK: string value = B:impl.value;
+// CHECK: }
+
// CHECK: --- Defs ---
// CHECK: def A1 {
@@ -8,7 +12,7 @@
// CHECK: }
// CHECK: def B1 {
-// CHECK: string value = A1.value;
+// CHECK: string value = ?;
// CHECK: }
class A {
More information about the llvm-commits
mailing list