[PATCH] D37546: TableGen: Resolve references when setting value

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 6 17:31:52 PDT 2017


arsenm created this revision.
Herald added subscribers: tpr, wdng.

If a record field was used as a template argument,
it wasn't fully evaluated leaving unfolded !ifs.

      

Fixes bug 30254 reduced testcase as reported.
Unfortunately, tablegen still errors when I remove
the workaround for this bug in the AMDGPU td files
so this might be incomplete.


https://reviews.llvm.org/D37546

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


Index: test/TableGen/bug30254.td
===================================================================
--- /dev/null
+++ test/TableGen/bug30254.td
@@ -0,0 +1,50 @@
+// RUN: llvm-tblgen %s | FileCheck %s
+// XFAIL: vg_leak
+
+class Operand {}
+
+def Enum : Operand {
+  int AAA = 1;
+  int BBB = 2;
+}
+
+// CHECK: class getString
+// CHECK-NEXT: string ret = !if(!eq(getString:Selector, 1), "AAA", !if(!eq(getString:Selector, 2), "BBB", ""));
+class getString<int Selector> {
+  string ret =
+    !if(!eq(Selector, Enum.AAA),  "AAA",
+    !if(!eq(Selector, Enum.BBB),  "BBB",
+    ""));
+}
+
+
+class S <int Selector, int SelectorCopy = Selector> {
+  string v1 = getString<Selector>.ret;  // <-- Doesnt resolve!
+  string v2 = getString<SelectorCopy>.ret; // <-- but this resolve!
+}
+
+// Works ok
+
+// CHECK: def C1 {
+// CHECK: int S:SelectorCopy = 1;
+// CHECK: string v1 = "AAA";
+// CHECK: string v2 = "AAA";
+def C1 : S <1>;
+
+// CHECK: def C2 {
+// CHECK: int S:SelectorCopy = 2;
+// CHECK: string v1 = "BBB";
+// CHECK: string v2 = "BBB";
+def C2 : S <2>;
+
+// Incorrect version, S:v1 doesnt resolve to a string
+
+// CHECK: def W1 {
+// CHECK: string v1 = "AAA";
+// CHECK: string v2 = "AAA";
+def W1 : S <Enum.AAA>;
+
+// CHECK: def W2 {
+// CHECK: string v1 = "BBB";
+// CHECK: string v2 = "BBB";
+def W2 : S <Enum.BBB>;
Index: lib/TableGen/TGParser.cpp
===================================================================
--- lib/TableGen/TGParser.cpp
+++ lib/TableGen/TGParser.cpp
@@ -142,6 +142,9 @@
     V = BitsInit::get(NewBits);
   }
 
+  if (!CurMultiClass)
+    V = V->resolveReferences(*CurRec, RV);
+
   if (RV->setValue(V)) {
     std::string InitType;
     if (BitsInit *BI = dyn_cast<BitsInit>(V))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37546.114105.patch
Type: text/x-patch
Size: 1725 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170907/04688012/attachment.bin>


More information about the llvm-commits mailing list