diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp index 590656786bc66..5e40c8f3cfa62 100644 --- a/llvm/lib/TableGen/Record.cpp +++ b/llvm/lib/TableGen/Record.cpp @@ -2094,10 +2094,12 @@ const Init *IsAOpInit::Fold() const { return IntInit::get(getRecordKeeper(), 1); if (isa(CheckType)) { - // If the target type is not a subclass of the expression type, or if - // the expression has fully resolved to a record, we know that it can't - // be of the required type. - if (!CheckType->typeIsConvertibleTo(TI->getType()) || isa(Expr)) + // If the target type is not a subclass of the expression type once the + // expression has been made concrete, or if the expression has fully + // resolved to a record, we know that it can't be of the required type. + if ((!CheckType->typeIsConvertibleTo(TI->getType()) && + Expr->isConcrete()) || + isa(Expr)) return IntInit::get(getRecordKeeper(), 0); } else { // We treat non-record types as not castable. diff --git a/llvm/test/TableGen/isa-non-primary.td b/llvm/test/TableGen/isa-non-primary.td new file mode 100644 index 0000000000000..96f9dfbc29d3a --- /dev/null +++ b/llvm/test/TableGen/isa-non-primary.td @@ -0,0 +1,33 @@ +// RUN: llvm-tblgen %s | FileCheck %s + +// CHECK: --- Defs --- +// CHECK: def Op1 { // Op +// CHECK-NEXT: string res = "yes"; +// CHECK-NEXT: } +// CHECK: def Op2 { // Op +// CHECK-NEXT: string res = "no"; +// CHECK-NEXT: } + +class A { + int x = a; +} + +class B : A { + bit y = 0; +} + +class C { + int z = !add(a, 16); +} + +class D : B, C; + +def E1 : D<5>; +def E2 : B<2>; + +class Op { + string res = !if(!isa(value), "yes", "no"); +} + +def Op1 : Op; +def Op2 : Op;