1 // RUN: not llvm-tblgen %s 2>&1 | FileCheck %s
3 // Test the assert statement at top level.
5 // CHECK: assertion failed
6 // CHECK-NOT: note: primary name is too short
7 // CHECK: note: primary name is too long
9 defvar Name = "Grace Brewster Murray Hopper";
11 assert !ge(!size(Name), 20), "primary name is too short: " # Name;
12 assert !le(!size(Name), 20), "primary name is too long: " # Name;
14 // CHECK: assertion failed
15 // CHECK: note: first name is incorrect
18 string name = "Fred Smith";
21 assert !eq(!substr(Rec01.name, 0, 3), "Jane"),
22 !strconcat("first name is incorrect: ", Rec01.name);
24 // CHECK: assertion failed
25 // CHECK: note: record Rec02 is broken
31 assert !not(Rec02.broken), "record Rec02 is broken";
33 // CHECK: assertion failed
34 // CHECK: note: cube of 9
37 int result = !mul(n, n, n);
40 assert !eq(Cube<9>.result, 81), "cube of 9 should be 729";
42 // CHECK: assertion failed
43 // CHECK: note: foreach i cannot be 2
44 // CHECK-NOT: note: foreach i cannot be 2
46 foreach i = 1...3 in {
47 assert !ne(i, 2), "foreach i cannot be 2";
51 // Test the assert statement in a record definition.
53 // CHECK: assertion failed
54 // CHECK-NOT: primary first name is not "Grace"
55 // CHECK: primary first name is not "Grack"
56 // CHECK: assertion failed
57 // CHECK: foo field should be
60 assert !eq(!substr(Name, 0, 5), "Grace"), "primary first name is not \"Grace\"";
61 assert !eq(!substr(Name, 0, 5), "Grack"), "primary first name is not \"Grack\"";
63 assert !eq(foo, "foo"), "foo field should be \"Foo\"";
66 // CHECK: assertion failed
67 // CHECK: note: magic field is incorrect: 42
71 assert !eq(magic, 13), "magic field is incorrect: " # magic;
75 // CHECK: assertion failed
76 // CHECK: note: var field has wrong value
79 defvar prefix = "foo_";
80 string var = prefix # "snork";
81 assert !eq(var, "foo_snorx"), "var field has wrong value: " # var;
84 // CHECK: assertion failed
85 // CHECK: note: kind field has wrong value
93 assert !eq(kind, 7), "kind field has wrong value: " # kind;
96 // CHECK: assertion failed
97 // CHECK: note: double_result should be
100 int double_result = !mul(result, 2);
101 assert !eq(double_result, 53), "double_result should be 54";
104 // Test the assert statement in a class definition.
106 class PersonName<string name> {
107 assert !le(!size(name), 32), "person name is too long: " # name;
111 class Person<string name, int age> : PersonName<name> {
112 assert !and(!ge(age, 1), !le(age, 120)),
113 "person age is invalid: " # age;
117 def Rec20 : Person<"Donald Knuth", 60>;
119 // CHECK: assertion failed
120 // CHECK: note: person name is too long
122 def Rec21 : Person<"Donald Uh Oh This Name Is Too Long Knuth", 50>;
124 // CHECK: assertion failed
125 // CHECK: note: person age is invalid
127 def Rec22 : Person<"Donald Knuth", 150>;
129 // Test the assert statement in an anonymous class invocation.
132 string Name = Person<"Margaret Heafield Hamilton", 25>.Name;
133 int Age = Person<"Margaret Heafield Hamilton", 25>.Age;
137 string Name = Person<"Margaret Heafield And More Middle Names Hamilton", 25>.Name;
138 int Age = Person<"Margaret Heafield Hamilton", 25>.Age;
142 string Name = Person<"Margaret Heafield Hamilton", 25>.Name;
143 int Age = Person<"Margaret Heafield Hamilton", 0>.Age;
146 // Test the assert statement in a multiclass.
148 // CHECK: assertion failed
149 // CHECK: note: MC1 id string is too long
150 // CHECK: assertion failed
151 // CHECK: note: MC1 seq is too high
153 multiclass MC1<string id, int seq> {
154 assert !le(!size(id), 5), "MC1 id string is too long";
155 assert !le(seq, 999999), "MC1 seq is too high";
163 defm Rec40 : MC1<"ILISP", 999>;
164 defm Rec41 : MC1<"ILISPX", 999>;
165 defm Rec42 : MC1<"ILISP", 999999999>;
167 // CHECK: assertion failed
168 // CHECK: note: MC2 phrase must be secret: secrex code
170 multiclass MC2<string phr> {
171 assert !eq(!substr(phr, 0, 6), "secret"), "MC2 phrase must be secret: " # phr;
178 multiclass MC3<string phr> {
179 defm _mc3 : MC2<phr>;
182 defm Rec43 : MC3<"secrex code">;
184 // CHECK: assertion failed
185 // CHECK: note: MC2 phrase must be secret: xecret code
187 multiclass MC4<string phr> : MC2<phr> {
191 defm Rec44 : MC4<"xecret code">;
193 // Test a defm in a multiclass that inherits from a class with asserts.
195 // CHECK: assertion failed
196 // CHECK: note: MC5 name must include a space: Ada_Lovelace
197 // CHECK: assertion failed
198 // CHECK: note: person age is invalid: 666
200 multiclass MC5<string phr, string name, int age> {
201 assert !ne(!find(name, " "), -1), "MC5 name must include a space: " # name;
203 defm _mc5 : MC2<phr>, Person<name, age>;
206 defm Rec45 : MC5<"secret password", "Ada_Lovelace", 666>;