[PATCH] D43555: TableGen: Fix type deduction for !foreach

Nicolai Hähnle via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 21 02:41:44 PST 2018


nhaehnle created this revision.
nhaehnle added reviewers: arsenm, craig.topper, tra, MartinO.
Herald added a subscriber: wdng.

In the case of !foreach(id, input-list, transform) where the type of
input-list is list<A> and the type of transform is B, we now correctly
deduce list<B> as the type of the !foreach.

Change-Id: Ia19dd65eecc5991dd648280ba6a15f6a20fd61de


Repository:
  rL LLVM

https://reviews.llvm.org/D43555

Files:
  lib/TableGen/TGParser.cpp
  test/TableGen/foreach.td


Index: test/TableGen/foreach.td
===================================================================
--- test/TableGen/foreach.td
+++ test/TableGen/foreach.td
@@ -7,12 +7,18 @@
 // CHECK: "NAME"
 
 // CHECK: Defs
+
+// CHECK: def DX {
+// CHECK:   list<string> x = ["0", "1", "2"];
+// CHECK: }
+
 // CHECK: Jr
 // CHECK: Sr
 
 // Variables for foreach
 class decls {
   string name;
+  int num;
 }
 
 def Decls : decls;
@@ -37,3 +43,9 @@
 def Juniors : C<People.values>;
 def Smiths : D<["NAME", "Jane Smith"]>;
 def Unprocessed : D<People.values>;
+
+class X<list<int> a> {
+    list<string> x = !foreach(Decls.num, a, !cast<string>(Decls.num));
+}
+
+def DX : X<[0, 1, 2]>;
Index: lib/TableGen/TGParser.cpp
===================================================================
--- lib/TableGen/TGParser.cpp
+++ lib/TableGen/TGParser.cpp
@@ -1084,6 +1084,14 @@
         return nullptr;
       }
       Type = MHSt->getType();
+      if (isa<ListRecTy>(Type)) {
+        TypedInit *RHSt = dyn_cast<TypedInit>(RHS);
+        if (!RHSt) {
+          TokError("could not get type of !foreach list elements");
+          return nullptr;
+        }
+        Type = RHSt->getType()->getListTy();
+      }
       break;
     }
     case tgtok::XSubst: {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43555.135216.patch
Type: text/x-patch
Size: 1245 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180221/4d9646a2/attachment.bin>


More information about the llvm-commits mailing list