File: ifstmt.td

package info (click to toggle)
llvm-toolchain-14 1%3A14.0.6-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,496,180 kB
  • sloc: cpp: 5,593,972; ansic: 986,872; asm: 585,869; python: 184,223; objc: 72,530; lisp: 31,119; f90: 27,793; javascript: 9,780; pascal: 9,762; sh: 9,482; perl: 7,468; ml: 5,432; awk: 3,523; makefile: 2,538; xml: 953; cs: 573; fortran: 567
file content (92 lines) | stat: -rw-r--r-- 1,941 bytes parent folder | download | duplicates (19)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// 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

// Test at top level.

// CHECK-NOT: def aNo
// CHECK: def aYes
if 0 then def aNo;
if 1 then def aYes;

// Test inside a foreach, with condition based on the iteration variable.

// CHECK: def bNotThree1
// CHECK: def bNotThree2
// CHECK: def bNotThree4
// CHECK: def bThree3
foreach i = 1...4 in {
  if !eq(i, 3) then {
    def "bThree" # i;
  } else {
    def "bNotThree" # i;
  }
}

// Test inside a multiclass, with condition based on a multiclass parameter.

multiclass Multi<int i> {
  def Unconditional;

  if !eq(i, 2) then
    def Cond;

  if !ge(i, 3) then
    def ThenRec;
  else
    def ElseRec;
}

// CHECK-NOT: def c1Cond
// CHECK: def c1ElseRec
// CHECK-NOT: def c1ThenRec
// CHECK: def c1Unconditional
defm c1: Multi<1>;

// CHECK: def c2Cond
// CHECK: def c2ElseRec
// CHECK-NOT: def c2ThenRec
// CHECK: def c2Unconditional
defm c2: Multi<2>;

// CHECK-NOT: def c3Cond
// CHECK-NOT: def c3ElseRec
// CHECK: def c3ThenRec
// CHECK: def c3Unconditional
defm c3: Multi<3>;

// Test resolution of the dangling-else ambiguity.

// CHECK: def dThenElse00
// CHECK-NOT: def dThenElse1
// CHECK-NOT: def dThenElse11
// CHECK: def dThenThen01
foreach i = 0...1 in
  foreach j = 0...1 in
    if !eq(i,0) then
      if !eq(j,1) then
        def "dThenThen"#i#j;
      else // binds to the inner if, not the outer one
        def "dThenElse"#i#j;

// Error tests: ensure you can't put an if inside a def or class.

#ifdef ERROR1
def baddef {
  int x = 3;
  // ERROR1: [[@LINE+1]]:3: error: Unknown token when expecting a type
  if 1 then {
    int y = 4;
  }
}
#endif

#ifdef ERROR2
class badclass<int i> {
  int x = 3;
  // ERROR2: [[@LINE+1]]:3: error: Unknown token when expecting a type
  if !eq(i, 5) then {
    int y = 4;
  }
}
#endif