2019-12-11 20:02:15 +08:00
|
|
|
// RUN: llvm-tblgen %s | FileCheck %s
|
|
|
|
// RUN: not llvm-tblgen -DERROR1 %s 2>&1 | FileCheck --check-prefix=ERROR1 %s
|
|
|
|
// RUN: not llvm-tblgen -DERROR2 %s 2>&1 | FileCheck --check-prefix=ERROR2 %s
|
|
|
|
// RUN: not llvm-tblgen -DERROR3 %s 2>&1 | FileCheck --check-prefix=ERROR3 %s
|
|
|
|
|
2020-10-21 01:50:49 +08:00
|
|
|
// !setop and !getop are deprecated in favor of !setdagop and !getdagop.
|
|
|
|
// Two tests retain the old names just to be sure they are still supported.
|
|
|
|
|
2019-12-11 20:02:15 +08:00
|
|
|
class Base;
|
|
|
|
class OtherBase;
|
|
|
|
|
|
|
|
def foo: Base;
|
|
|
|
def bar: Base;
|
|
|
|
def qux: OtherBase;
|
|
|
|
|
|
|
|
def test {
|
|
|
|
dag orig = (foo 1, 2:$a, $b);
|
|
|
|
dag another = (qux "hello", $world);
|
|
|
|
|
|
|
|
// CHECK: dag replaceWithBar = (bar 1, 2:$a, ?:$b);
|
|
|
|
dag replaceWithBar = !setop(orig, bar);
|
|
|
|
|
|
|
|
// CHECK: dag replaceWithBaz = (qux 1, 2:$a, ?:$b);
|
2020-10-21 01:50:49 +08:00
|
|
|
dag replaceWithBaz = !setdagop(orig, qux);
|
2019-12-11 20:02:15 +08:00
|
|
|
|
|
|
|
// CHECK: Base getopWithCast = foo;
|
|
|
|
Base getopWithCast = !getop<Base>(orig);
|
|
|
|
|
|
|
|
// CHECK: dag getopToSetop = (foo "hello", ?:$world);
|
2020-10-21 01:50:49 +08:00
|
|
|
dag getopToSetop = !setdagop(another, !getdagop(orig));
|
2019-12-11 20:02:15 +08:00
|
|
|
|
|
|
|
// CHECK: dag getopToBangDag = (foo 1:$a, 2:$b, 3:$c);
|
2020-10-21 01:50:49 +08:00
|
|
|
dag getopToBangDag = !dag(!getdagop(orig), [1, 2, 3], ["a", "b", "c"]);
|
2019-12-11 20:02:15 +08:00
|
|
|
|
|
|
|
// CHECK: dag getopToDagInit = (foo "it worked");
|
2020-10-21 01:50:49 +08:00
|
|
|
dag getopToDagInit = (!getdagop(orig) "it worked");
|
2019-12-11 20:02:15 +08:00
|
|
|
|
|
|
|
#ifdef ERROR1
|
2020-10-21 01:50:49 +08:00
|
|
|
// !getdagop(...) has a static type of 'any record at all, with no
|
2019-12-11 20:02:15 +08:00
|
|
|
// required superclasses'. That's too general to use in an
|
|
|
|
// assignment whose LHS demands an instance of Base, so we expect a
|
|
|
|
// static (parse-time) type-checking error.
|
|
|
|
|
2020-10-21 01:50:49 +08:00
|
|
|
// ERROR1: error: Field 'noCast' of type 'Base' is incompatible with value '!getdagop(orig)' of type '{}'
|
|
|
|
Base noCast = !getdagop(orig);
|
2019-12-11 20:02:15 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ERROR2
|
|
|
|
// Here, we expect a _dynamic_ type error, when it turns out at
|
|
|
|
// evaluation time that the operator of 'another' is a record that
|
|
|
|
// isn't an instance of the specified base class.
|
|
|
|
|
2020-10-21 01:50:49 +08:00
|
|
|
// ERROR2: error: Expected type 'Base', got 'OtherBase' in: !getdagop((qux "hello", ?:$world))
|
|
|
|
Base badCast = !getdagop<Base>(another);
|
2019-12-11 20:02:15 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ERROR3
|
2020-10-21 01:50:49 +08:00
|
|
|
// Obviously, you shouldn't be able to give any type to !getdagop that
|
2019-12-11 20:02:15 +08:00
|
|
|
// isn't a class type.
|
|
|
|
|
2020-10-21 01:50:49 +08:00
|
|
|
// ERROR3: error: type for !getdagop must be a record type
|
|
|
|
int ridiculousCast = !getdagop<int>(orig);
|
2019-12-11 20:02:15 +08:00
|
|
|
#endif
|
|
|
|
}
|