[PATCH] D53068: TableGen: fix assert in !cast when used out of definition in a multiclass

Valery Pykhtin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 10 02:43:50 PDT 2018


vpykhtin created this revision.
vpykhtin added reviewers: tra, nhaehnle.
Herald added a subscriber: llvm-commits.

The attached testcase asserts on !cast without the patch. The reason is that there is no CurRec when !cast used inside foreach. Let's postpone CurRec check until isFinal.


Repository:
  rL LLVM

https://reviews.llvm.org/D53068

Files:
  lib/TableGen/Record.cpp
  test/TableGen/cast-multiclass.td


Index: test/TableGen/cast-multiclass.td
===================================================================
--- /dev/null
+++ test/TableGen/cast-multiclass.td
@@ -0,0 +1,23 @@
+// RUN: llvm-tblgen %s | FileCheck %s
+
+class AClass<bit C> {
+  bit Cond = C;
+}
+
+def A0: AClass<0>;
+def A1: AClass<1>;
+
+class BoolToList<bit Value> {
+  list<int> ret = !if(Value, [1]<int>, []<int>);
+}
+
+multiclass P<string AStr> {
+  foreach i = BoolToList<!cast<AClass>(AStr).Cond>.ret in
+    def SubDef;
+}
+
+// CHECK-NOT: def XSubDef
+defm X : P<"A0">;
+
+// CHECK: def YSubDef
+defm Y : P<"A1">;
\ No newline at end of file
Index: lib/TableGen/Record.cpp
===================================================================
--- lib/TableGen/Record.cpp
+++ lib/TableGen/Record.cpp
@@ -709,6 +709,8 @@
         return StringInit::get(LHSi->getAsString());
     } else if (isa<RecordRecTy>(getType())) {
       if (StringInit *Name = dyn_cast<StringInit>(LHS)) {
+        if (!CurRec && !IsFinal)
+          break;
         assert(CurRec && "NULL pointer");
         Record *D;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53068.168960.patch
Type: text/x-patch
Size: 1070 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181010/eadb36f6/attachment.bin>


More information about the llvm-commits mailing list