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 5// Test at top level. 6 7// CHECK-NOT: def aNo 8// CHECK: def aYes 9if 0 then def aNo; 10if 1 then def aYes; 11 12// Test inside a foreach, with condition based on the iteration variable. 13 14// CHECK: def bNotThree1 15// CHECK: def bNotThree2 16// CHECK: def bNotThree4 17// CHECK: def bThree3 18foreach i = 1...4 in { 19 if !eq(i, 3) then { 20 def "bThree" # i; 21 } else { 22 def "bNotThree" # i; 23 } 24} 25 26// Test inside a multiclass, with condition based on a multiclass parameter. 27 28multiclass Multi<int i> { 29 def Unconditional; 30 31 if !eq(i, 2) then 32 def Cond; 33 34 if !ge(i, 3) then 35 def ThenRec; 36 else 37 def ElseRec; 38} 39 40// CHECK-NOT: def c1Cond 41// CHECK: def c1ElseRec 42// CHECK-NOT: def c1ThenRec 43// CHECK: def c1Unconditional 44defm c1: Multi<1>; 45 46// CHECK: def c2Cond 47// CHECK: def c2ElseRec 48// CHECK-NOT: def c2ThenRec 49// CHECK: def c2Unconditional 50defm c2: Multi<2>; 51 52// CHECK-NOT: def c3Cond 53// CHECK-NOT: def c3ElseRec 54// CHECK: def c3ThenRec 55// CHECK: def c3Unconditional 56defm c3: Multi<3>; 57 58// Test resolution of the dangling-else ambiguity. 59 60// CHECK: def dThenElse00 61// CHECK-NOT: def dThenElse1 62// CHECK-NOT: def dThenElse11 63// CHECK: def dThenThen01 64foreach i = 0...1 in 65 foreach j = 0...1 in 66 if !eq(i,0) then 67 if !eq(j,1) then 68 def "dThenThen"#i#j; 69 else // binds to the inner if, not the outer one 70 def "dThenElse"#i#j; 71 72// Error tests: ensure you can't put an if inside a def or class. 73 74#ifdef ERROR1 75def baddef { 76 int x = 3; 77 // ERROR1: [[@LINE+1]]:3: error: Unknown token when expecting a type 78 if 1 then { 79 int y = 4; 80 } 81} 82#endif 83 84#ifdef ERROR2 85class badclass<int i> { 86 int x = 3; 87 // ERROR2: [[@LINE+1]]:3: error: Unknown token when expecting a type 88 if !eq(i, 5) then { 89 int y = 4; 90 } 91} 92#endif 93