[PATCH] D100247: [TableGen] Fix bug in recent change to ListInit::convertInitListSlice()

Paul C. Anagnostopoulos via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 10 06:27:17 PDT 2021


Paul-C-Anagnostopoulos created this revision.
Paul-C-Anagnostopoulos added reviewers: lattner, dsanders.
Herald added a subscriber: hiraditya.
Paul-C-Anagnostopoulos requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

I recently modified ListInit::convertInitListSlice() to make it consistent with the list slice rules. I added two lines of code and managed to get 50% of them wrong. Further, I enhanced the ListSlices.td test and managed not to detect my own mistake.

This patch fixes the fix. Thanks to @dsanders for help with this.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100247

Files:
  llvm/lib/TableGen/Record.cpp
  llvm/test/TableGen/ListSlices.td


Index: llvm/test/TableGen/ListSlices.td
===================================================================
--- llvm/test/TableGen/ListSlices.td
+++ llvm/test/TableGen/ListSlices.td
@@ -9,14 +9,14 @@
 // CHECK:   list<int> ShowVar1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 // CHECK:   int ShowVar2 = 0
 // CHECK:   list<int> ShowVar3 = [2, 3, 4, 5]
-// CHECK:   int ShowVar4 = 0
+// CHECK:   int ShowVar4 = 2
 // CHECK:   list<int> ShowVar5 = [2, 3, 4, 5]
 
 defvar Var1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
 defvar Var2 = Var1[0];
 defvar Var3 = Var1[2...5];
 
-defvar Var4 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9][0];
+defvar Var4 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9][2];
 defvar Var5 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9][2...5];
 
 def Rec00 { // Display the defvars.
@@ -96,12 +96,30 @@
 
 // CHECK: def Rec08
 // CHECK:   list<list<string>> Array = {{.*}}"foo", "bar", "snork"], ["zoo", "quux", "flarp"]]
-// CHECK:   string Snork = "snork"
+// CHECK:   string Flarp = "flarp"
 // CHECK:   list<string> ZooQuux = ["zoo", "quux"]
 
 def Rec08 {
   list<list<string>> Array = [["foo", "bar", "snork"],
                               ["zoo", "quux", "flarp"]];
-  string Snork = Array[0][2];
+  string Flarp = Array[1][2];
   list<string> ZooQuux = Array[1][0...1];
 }
+
+// Test uninitialized list elements.
+
+// CHECK: def Rec09
+// CHECK:   int Zero = ?;
+// CHECK:   list<int> TwoFive = [2, 3, ?, 5];
+// CHECK: def Rec10
+// CHECK:   list<int> TwoFive = [2, 3, ?, 5];
+
+def Rec09 : Class1<[?, ?, 2, 3, ?, 5, ?]>;
+
+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.
Index: llvm/lib/TableGen/Record.cpp
===================================================================
--- llvm/lib/TableGen/Record.cpp
+++ llvm/lib/TableGen/Record.cpp
@@ -615,8 +615,11 @@
 }
 
 Init *ListInit::convertInitListSlice(ArrayRef<unsigned> Elements) const {
-  if (Elements.size() == 1)
-    return getElement(0);
+  if (Elements.size() == 1) {
+    if (Elements[0] >= size())
+      return nullptr;
+    return getElement(Elements[0]);
+  }
 
   SmallVector<Init*, 8> Vals;
   Vals.reserve(Elements.size());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100247.336609.patch
Type: text/x-patch
Size: 2286 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210410/c62dbe87/attachment.bin>


More information about the llvm-commits mailing list