[llvm] 985ab6e - [TableGen] Fix two bugs in 'defm' when complex 'assert' is involved.

Paul C. Anagnostopoulos via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 30 08:33:18 PDT 2021


Author: Paul C. Anagnostopoulos
Date: 2021-04-30T11:31:06-04:00
New Revision: 985ab6e1fa575fc41ebfdafbba401e5787661584

URL: https://github.com/llvm/llvm-project/commit/985ab6e1fa575fc41ebfdafbba401e5787661584
DIFF: https://github.com/llvm/llvm-project/commit/985ab6e1fa575fc41ebfdafbba401e5787661584.diff

LOG: [TableGen] Fix two bugs in 'defm' when complex 'assert' is involved.

This patch fixes two bugs that arise when a 'defm' inherits from a multiclass
and also from a class with assertions.

Differential Revision: https://reviews.llvm.org/D101626

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/TableGen/Record.h b/llvm/include/llvm/TableGen/Record.h
index 717347ae03bad..713d9375448cc 100644
--- a/llvm/include/llvm/TableGen/Record.h
+++ b/llvm/include/llvm/TableGen/Record.h
@@ -1529,7 +1529,7 @@ class Record {
   // 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) { }
 

diff  --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp
index 8d228d73f2531..cae0306b23b72 100644
--- a/llvm/lib/TableGen/TGParser.cpp
+++ b/llvm/lib/TableGen/TGParser.cpp
@@ -292,6 +292,9 @@ bool TGParser::AddSubClass(RecordsEntry &Entry, SubClassReference &SubClass) {
   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;

diff  --git a/llvm/test/TableGen/assert.td b/llvm/test/TableGen/assert.td
index fb8f7beccc89c..d616adcb5d0d1 100644
--- a/llvm/test/TableGen/assert.td
+++ b/llvm/test/TableGen/assert.td
@@ -189,3 +189,18 @@ multiclass MC4<string phr> : MC2<phr> {
 }
 
 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>;


        


More information about the llvm-commits mailing list