1// RUN: llvm-tblgen %s | FileCheck %s 2// RUN: not llvm-tblgen -DERROR1 %s 2>&1 | FileCheck --check-prefix=ERROR1 %s 3// RUN: not llvm-tblgen -DERROR2 %s 2>&1 | FileCheck --check-prefix=ERROR2 %s 4// RUN: not llvm-tblgen -DERROR3 %s 2>&1 | FileCheck --check-prefix=ERROR3 %s 5 6// !setop and !getop are deprecated in favor of !setdagop and !getdagop. 7// Two tests retain the old names just to be sure they are still supported. 8 9class Base; 10class OtherBase; 11 12def foo: Base; 13def bar: Base; 14def qux: OtherBase; 15 16def test { 17 dag orig = (foo 1, 2:$a, $b); 18 dag another = (qux "hello", $world); 19 20 // CHECK: dag replaceWithBar = (bar 1, 2:$a, ?:$b); 21 dag replaceWithBar = !setop(orig, bar); 22 23 // CHECK: dag replaceWithBaz = (qux 1, 2:$a, ?:$b); 24 dag replaceWithBaz = !setdagop(orig, qux); 25 26 // CHECK: Base getopWithCast = foo; 27 Base getopWithCast = !getop<Base>(orig); 28 29 // CHECK: dag getopToSetop = (foo "hello", ?:$world); 30 dag getopToSetop = !setdagop(another, !getdagop(orig)); 31 32 // CHECK: dag getopToBangDag = (foo 1:$a, 2:$b, 3:$c); 33 dag getopToBangDag = !dag(!getdagop(orig), [1, 2, 3], ["a", "b", "c"]); 34 35 // CHECK: dag getopToDagInit = (foo "it worked"); 36 dag getopToDagInit = (!getdagop(orig) "it worked"); 37 38#ifdef ERROR1 39 // !getdagop(...) has a static type of 'any record at all, with no 40 // required superclasses'. That's too general to use in an 41 // assignment whose LHS demands an instance of Base, so we expect a 42 // static (parse-time) type-checking error. 43 44 // ERROR1: error: Field 'noCast' of type 'Base' is incompatible with value '!getdagop(orig)' of type '{}' 45 Base noCast = !getdagop(orig); 46#endif 47 48#ifdef ERROR2 49 // Here, we expect a _dynamic_ type error, when it turns out at 50 // evaluation time that the operator of 'another' is a record that 51 // isn't an instance of the specified base class. 52 53 // ERROR2: error: Expected type 'Base', got 'OtherBase' in: !getdagop((qux "hello", ?:$world)) 54 Base badCast = !getdagop<Base>(another); 55#endif 56 57#ifdef ERROR3 58 // Obviously, you shouldn't be able to give any type to !getdagop that 59 // isn't a class type. 60 61 // ERROR3: error: type for !getdagop must be a record type 62 int ridiculousCast = !getdagop<int>(orig); 63#endif 64} 65