[PATCH] D101626: [TableGen] Fix two bugs in 'defm' when a complex 'assert' is involved

Paul C. Anagnostopoulos via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 30 06:38:50 PDT 2021


Paul-C-Anagnostopoulos created this revision.
Paul-C-Anagnostopoulos added reviewers: jansvoboda11, dblaikie, craig.topper.
Herald added a subscriber: hiraditya.
Paul-C-Anagnostopoulos requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This patch fixes two bugs that arise when a 'defm' inherits from a multiclass and also from a class with assertions. I discovered them while adding assertions to the Clang TableGen files.

I'm not sure whether this warrants a Phabricator review, but it certainly can't hurt.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101626

Files:
  llvm/include/llvm/TableGen/Record.h
  llvm/lib/TableGen/TGParser.cpp
  llvm/test/TableGen/assert.td


Index: llvm/test/TableGen/assert.td
===================================================================
--- llvm/test/TableGen/assert.td
+++ llvm/test/TableGen/assert.td
@@ -189,3 +189,18 @@
 }
 
 defm Rec44 : MC4<"xecret code">;
+
+// Test a defm in a multiclass that inherits from a class with asserts.
+
+// CHECK: assertion failed
+// CHECK: note: MC5 name must include a space: Ada_Lovelace
+// CHECK: assertion failed
+// CHECK: note: person age is invalid: 666
+
+multiclass MC5<string phr, string name, int age> {
+  assert !ne(!find(name, " "), -1), "MC5 name must include a space: " # name;
+
+  defm _mc5 : MC2<phr>, Person<name, age>;
+}
+
+defm Rec45 : MC5<"secret password", "Ada_Lovelace", 666>;
Index: llvm/lib/TableGen/TGParser.cpp
===================================================================
--- llvm/lib/TableGen/TGParser.cpp
+++ llvm/lib/TableGen/TGParser.cpp
@@ -292,6 +292,9 @@
   if (Entry.Rec)
     return AddSubClass(Entry.Rec.get(), SubClass);
 
+  if (Entry.Assertion)
+    return false;
+
   for (auto &E : Entry.Loop->Entries) {
     if (AddSubClass(E, SubClass))
       return true;
Index: llvm/include/llvm/TableGen/Record.h
===================================================================
--- llvm/include/llvm/TableGen/Record.h
+++ llvm/include/llvm/TableGen/Record.h
@@ -1529,7 +1529,7 @@
   // original record. All other fields can be copied normally.
   Record(const Record &O)
     : Name(O.Name), Locs(O.Locs), TemplateArgs(O.TemplateArgs),
-      Values(O.Values), SuperClasses(O.SuperClasses),
+      Values(O.Values), Assertions(O.Assertions), SuperClasses(O.SuperClasses),
       TrackedRecords(O.TrackedRecords), ID(LastID++),
       IsAnonymous(O.IsAnonymous), IsClass(O.IsClass) { }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101626.341880.patch
Type: text/x-patch
Size: 1740 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210430/306cdc35/attachment.bin>


More information about the llvm-commits mailing list