[llvm] r325891 - Revert "TableGen: Fix typeIsConvertibleTo for record types"

Nicolai Haehnle via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 23 03:31:49 PST 2018


Author: nha
Date: Fri Feb 23 03:31:49 2018
New Revision: 325891

URL: http://llvm.org/viewvc/llvm-project?rev=325891&view=rev
Log:
Revert "TableGen: Fix typeIsConvertibleTo for record types"

This reverts r325884.

Clang's TableGen has dependencies on the exact ordering of superclasses.
Revert this change fully for now to fix the build.

Change-Id: Ib297f5571cc7809f00838702ad7ab53d47335b26

Removed:
    llvm/trunk/test/TableGen/if-type.td
Modified:
    llvm/trunk/lib/TableGen/Record.cpp
    llvm/trunk/lib/TableGen/TGParser.cpp
    llvm/trunk/test/TableGen/if.td

Modified: llvm/trunk/lib/TableGen/Record.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/Record.cpp?rev=325891&r1=325890&r2=325891&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/Record.cpp (original)
+++ llvm/trunk/lib/TableGen/Record.cpp Fri Feb 23 03:31:49 2018
@@ -141,6 +141,10 @@ bool RecordRecTy::typeIsConvertibleTo(co
   if (RTy->getRecord() == Rec || Rec->isSubClassOf(RTy->getRecord()))
     return true;
 
+  for (const auto &SCPair : RTy->getRecord()->getSuperClasses())
+    if (Rec->isSubClassOf(SCPair.first))
+      return true;
+
   return false;
 }
 
@@ -169,16 +173,6 @@ RecTy *llvm::resolveTypes(RecTy *T1, Rec
         return NewType2;
     }
   }
-
-  if (ListRecTy *ListTy1 = dyn_cast<ListRecTy>(T1)) {
-    if (ListRecTy *ListTy2 = dyn_cast<ListRecTy>(T2)) {
-      RecTy* NewType = resolveTypes(ListTy1->getElementType(),
-                                    ListTy2->getElementType());
-      if (NewType)
-        return NewType->getListTy();
-    }
-  }
-
   return nullptr;
 }
 

Modified: llvm/trunk/lib/TableGen/TGParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/TGParser.cpp?rev=325891&r1=325890&r2=325891&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/TGParser.cpp (original)
+++ llvm/trunk/lib/TableGen/TGParser.cpp Fri Feb 23 03:31:49 2018
@@ -198,8 +198,6 @@ bool TGParser::AddSubClass(Record *CurRe
 
   // Since everything went well, we can now set the "superclass" list for the
   // current record.
-  CurRec->addSuperClass(SC, SubClass.RefRange);
-
   ArrayRef<std::pair<Record *, SMRange>> SCs = SC->getSuperClasses();
   for (const auto &SCPair : SCs) {
     if (CurRec->isSubClassOf(SCPair.first))
@@ -207,6 +205,11 @@ bool TGParser::AddSubClass(Record *CurRe
                    "Already subclass of '" + SCPair.first->getName() + "'!\n");
     CurRec->addSuperClass(SCPair.first, SCPair.second);
   }
+
+  if (CurRec->isSubClassOf(SC))
+    return Error(SubClass.RefRange.Start,
+                 "Already subclass of '" + SC->getName() + "'!\n");
+  CurRec->addSuperClass(SC, SubClass.RefRange);
   return false;
 }
 
@@ -1064,10 +1067,12 @@ Init *TGParser::ParseOperation(Record *C
         return nullptr;
       }
 
-      Type = resolveTypes(MHSTy, RHSTy);
-      if (!Type) {
-        TokError(Twine("inconsistent types '") + MHSTy->getAsString() +
-                 "' and '" + RHSTy->getAsString() + "' for !if");
+      if (MHSTy->typeIsConvertibleTo(RHSTy)) {
+        Type = RHSTy;
+      } else if (RHSTy->typeIsConvertibleTo(MHSTy)) {
+        Type = MHSTy;
+      } else {
+        TokError("inconsistent types for !if");
         return nullptr;
       }
       break;

Removed: llvm/trunk/test/TableGen/if-type.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/TableGen/if-type.td?rev=325890&view=auto
==============================================================================
--- llvm/trunk/test/TableGen/if-type.td (original)
+++ llvm/trunk/test/TableGen/if-type.td (removed)
@@ -1,11 +0,0 @@
-// RUN: not llvm-tblgen %s 2>&1 | FileCheck %s
-// XFAIL: vg_leak
-
-class A<int dummy> {}
-class B<int dummy> : A<dummy> {}
-class C<int dummy> : A<dummy> {}
-
-// CHECK: Value 'x' of type 'C' is incompatible with initializer '{{.*}}' of type 'A'
-class X<int cc, B b, C c> {
-  C x = !if(cc, b, c);
-}

Modified: llvm/trunk/test/TableGen/if.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/TableGen/if.td?rev=325891&r1=325890&r2=325891&view=diff
==============================================================================
--- llvm/trunk/test/TableGen/if.td (original)
+++ llvm/trunk/test/TableGen/if.td Fri Feb 23 03:31:49 2018
@@ -69,34 +69,10 @@ class I2<int c> : I1<c>;
 // CHECK-NEXT: int i = 0;
 def DI1: I1<1>;
 
-// CHECK: def DI2 {
+// CHECK: def DI2 {     // I1 I2
 // CHECK-NEXT: int i = 0;
 def DI2: I2<1>;
 
-// Check that !if with operands of different subtypes can initialize a
-// supertype variable.
-//
-// CHECK: def EXd1 {
-// CHECK:   E x = E1d;
-// CHECK: }
-//
-// CHECK: def EXd2 {
-// CHECK:   E x = E2d;
-// CHECK: }
-class E<int dummy> {}
-class E1<int dummy> : E<dummy> {}
-class E2<int dummy> : E<dummy> {}
-
-class EX<int cc, E1 b, E2 c> {
-  E x = !if(cc, b, c);
-}
-
-def E1d : E1<0>;
-def E2d : E2<0>;
-
-def EXd1 : EX<1, E1d, E2d>;
-def EXd2 : EX<0, E1d, E2d>;
-
 // CHECK:      def One
 // CHECK-NEXT: list<int> first = [1, 2, 3];
 // CHECK-NEXT: list<int> rest = [1, 2, 3];




More information about the llvm-commits mailing list