1RUN: FileCheck --input-file %s %s
2
3; We use CHECK-NEXT directives to force a match on all lines with digits.
4
5; Numeric variable definition without spaces.
6DEF NO SPC
710
8CHECK-LABEL: DEF NO SPC
9CHECK-NEXT: [[#VAR1:]]
10
11; Numeric variable definition with different spacing.
12DEF SPC
1311
1411
1511
16CHECK-LABEL: DEF SPC
17CHECK-NEXT: [[# VAR1a:]]
18CHECK-NEXT: [[# VAR1b :]]
19CHECK-NEXT: [[# VAR1c : ]]
20
21; Numeric variable redefinition.
22REDEF NO SPC
2311
24CHECK-LABEL: REDEF
25CHECK-NEXT: [[#VAR1:]]
26
27; Numeric expressions using variables defined on other lines without spaces.
28USE NO SPC
2911
3012
3110
3211
3311
3411
35CHECK-LABEL: USE
36CHECK-NEXT: [[#VAR1]]
37CHECK-NEXT: [[#VAR1+1]]
38CHECK-NEXT: [[#VAR1-1]]
39CHECK-NEXT: [[#VAR1a]]
40CHECK-NEXT: [[#VAR1b]]
41CHECK-NEXT: [[#VAR1c]]
42
43; Numeric expressions using variables defined on other lines with different
44; spacing.
45USE SPC
4611
4711
4812
4912
5012
5112
5210
5310
5410
5510
56CHECK-LABEL: USE SPC
57CHECK-NEXT: [[# VAR1]]
58CHECK-NEXT: [[# VAR1 ]]
59CHECK-NEXT: [[# VAR1+1]]
60CHECK-NEXT: [[# VAR1 +1]]
61CHECK-NEXT: [[# VAR1 + 1]]
62CHECK-NEXT: [[# VAR1 + 1 ]]
63CHECK-NEXT: [[# VAR1-1]]
64CHECK-NEXT: [[# VAR1 -1]]
65CHECK-NEXT: [[# VAR1 - 1]]
66CHECK-NEXT: [[# VAR1 - 1 ]]
67
68; Numeric expressions using variables defined on other lines and an immediate
69; interpreted as an unsigned value.
70; Note: 9223372036854775819 = 0x8000000000000000 + 11
71;       9223372036854775808 = 0x8000000000000000
72USE UNSIGNED IMM
739223372036854775819
74CHECK-LABEL: USE UNSIGNED IMM
75CHECK-NEXT: [[#VAR1+9223372036854775808]]
76
77; Numeric expressions using more than one variable defined on other lines.
78USE MULTI VAR
7931
8042
81CHECK-LABEL: USE MULTI VAR
82CHECK-NEXT: [[#VAR2:]]
83CHECK-NEXT: [[#VAR1+VAR2]]
84
85; Numeric expression using a variable defined from a numeric expression.
86DEF EXPR GOOD MATCH
8742
8841
89; CHECK-LABEL: DEF EXPR GOOD MATCH
90; CHECK-NEXT: [[# VAR42:VAR1+31]]
91; CHECK-NEXT: [[# VAR42-1]]
92
93; Empty numeric expression.
94EMPTY NUM EXPR
95foo 104 bar
96; CHECK-LABEL: EMPTY NUM EXPR
97; CHECK-NEXT: foo [[#]] bar
98
99; Numeric expression using undefined variables.
100RUN: not FileCheck --check-prefix UNDEF-USE --input-file %s %s 2>&1 \
101RUN:   | FileCheck --strict-whitespace --check-prefix UNDEF-USE-MSG %s
102
103UNDEF VAR USE
104UNDEFVAR: 11
105UNDEF-USE-LABEL: UNDEF VAR USE
106UNDEF-USE-NEXT: UNDEFVAR: [[#UNDEFVAR1+UNDEFVAR2]]
107UNDEF-USE-MSG: numeric-expression.txt:[[#@LINE-1]]:17: error: {{U}}NDEF-USE-NEXT: expected string not found in input
108UNDEF-USE-MSG-NEXT:      {{U}}NDEF-USE-NEXT: UNDEFVAR: {{\[\[#UNDEFVAR1\+UNDEFVAR2\]\]}}
109UNDEF-USE-MSG-NEXT:     {{^}}                ^{{$}}
110UNDEF-USE-MSG-NEXT:      numeric-expression.txt:[[#@LINE-6]]:1: note: scanning from here
111UNDEF-USE-MSG-NEXT:      UNDEFVAR: 11
112UNDEF-USE-MSG-NEXT: {{^}}^{{$}}
113UNDEF-USE-MSG-NEXT:      numeric-expression.txt:[[#@LINE-9]]:1: note: uses undefined variable(s): "UNDEFVAR1" "UNDEFVAR2"
114UNDEF-USE-MSG-NEXT:      UNDEFVAR: 11
115UNDEF-USE-MSG-NEXT: {{^}}^{{$}}
116
117; Numeric expression with unsupported operator.
118RUN: not FileCheck -D#NUMVAR=10 --check-prefix INVAL-OP --input-file %s %s 2>&1 \
119RUN:   | FileCheck --strict-whitespace --check-prefix INVAL-OP-MSG %s
120
121INVALID OPERATOR
122NUMVAR*2: 22
123INVAL-OP-LABEL: INVALID OPERATOR
124INVAL-OP-NEXT: NUMVAR*2: [[#NUMVAR*2]]
125INVAL-OP-MSG: numeric-expression.txt:[[#@LINE-1]]:35: error: unsupported operation '*'
126INVAL-OP-MSG-NEXT: {{I}}NVAL-OP-NEXT: NUMVAR*2: {{\[\[#NUMVAR\*2\]\]}}
127INVAL-OP-MSG-NEXT:     {{^}}                                  ^{{$}}
128
129; Name conflict between Numeric variable definition and string variable
130; definition whether from the command-line or input text.
131RUN: not FileCheck --check-prefixes CONFLICT,CONFLICT1,CONFLICT2 --input-file %s %s 2>&1 \
132RUN:   | FileCheck --strict-whitespace --check-prefix INPUT-STR-CONFLICT %s
133RUN: not FileCheck -D#NUMVAR=42 --check-prefixes CONFLICT,CONFLICT2 --input-file %s %s 2>&1 \
134RUN:   | FileCheck --strict-whitespace --check-prefix INPUT-STR-CONFLICT %s
135RUN: not FileCheck -D#NUMVAR=42 -DNUMVAR=foobar --check-prefix CONFLICT --input-file %s %s 2>&1 \
136RUN:   | FileCheck --strict-whitespace --check-prefix CLI-STR-CONFLICT %s
137RUN: not FileCheck --check-prefixes CONFLICT,CONFLICT3,CONFLICT4 --input-file %s %s 2>&1 \
138RUN:   | FileCheck --strict-whitespace --check-prefix INPUT-NUM-CONFLICT %s
139RUN: not FileCheck -DSTRVAR=foobar --check-prefixes CONFLICT,CONFLICT4 --input-file %s %s 2>&1 \
140RUN:   | FileCheck --strict-whitespace --check-prefix INPUT-NUM-CONFLICT %s
141RUN: not FileCheck -DSTRVAR=foobar -D#STRVAR=42 --check-prefix CONFLICT --input-file %s %s 2>&1 \
142RUN:   | FileCheck --strict-whitespace --check-prefix CLI-NUM-CONFLICT %s
143
144STRVAR NUMVAR CONFLICT
145redef1 42
146foobar
147redef2 42
148CONFLICT-LABEL: STRVAR NUMVAR CONFLICT
149CONFLICT1-NEXT: redef1 [[#NUMVAR:]]
150CONFLICT2: [[NUMVAR:foo.*]]
151CONFLICT3: [[STRVAR:foo.*]]
152CONFLICT4: redef2 [[#STRVAR:]]
153INPUT-STR-CONFLICT: numeric-expression.txt:[[#@LINE-3]]:14: error: numeric variable with name 'NUMVAR' already exists
154INPUT-STR-CONFLICT-NEXT: {{C}}ONFLICT2: {{\[\[NUMVAR:foo\.\*\]\]}}
155INPUT-STR-CONFLICT-NEXT:    {{^}}             ^{{$}}
156CLI-STR-CONFLICT: Global defines:2:19: error: numeric variable with name 'NUMVAR' already exists
157CLI-STR-CONFLICT-NEXT:      Global define #2: NUMVAR=foobar
158CLI-STR-CONFLICT-NEXT: {{^}}                  ^{{$}}
159INPUT-NUM-CONFLICT: numeric-expression.txt:[[#@LINE-7]]:22: error: string variable with name 'STRVAR' already exists
160 INPUT-NUM-CONFLICT-NEXT: CONFLICT4: redef2 {{\[\[#STRVAR:\]\]}}
161INPUT-NUM-CONFLICT-NEXT: {{^}}                     ^{{$}}
162CLI-NUM-CONFLICT: Global defines:2:45: error: string variable with name 'STRVAR' already exists
163 CLI-NUM-CONFLICT-NEXT: Global define #2: #STRVAR=42 (parsed as: {{\[\[#STRVAR:42\]\]}})
164CLI-NUM-CONFLICT-NEXT: {{^}}                                            ^{{$}}
165
166; Numeric variable definition with too big value.
167RUN: not FileCheck --check-prefix BIGVAL --input-file %s %s 2>&1 \
168RUN:   | FileCheck --strict-whitespace --check-prefix BIGVAL-MSG %s
169
170BIG VALUE
171NUMVAR: 10000000000000000000000
172BIGVAL-LABEL: BIG VALUE
173BIGVAL-NEXT: NUMVAR: [[#NUMVAR:]]
174BIGVAL-MSG: numeric-expression.txt:[[#@LINE-3]]:9: error: Unable to represent numeric value
175 BIGVAL-MSG-NEXT: {{N}}UMVAR: 10000000000000000000000
176BIGVAL-MSG-NEXT: {{^}}        ^{{$}}
177
178; Verify that when a variable is set to an expression the expression is still
179; checked.
180RUN: not FileCheck --check-prefix DEF-EXPR-FAIL --input-file %s %s 2>&1 \
181RUN:   | FileCheck --strict-whitespace --check-prefix DEF-EXPR-FAIL-MSG %s
182
183DEF EXPR WRONG MATCH
18420
18543
186DEF-EXPR-FAIL-LABEL: DEF EXPR WRONG MATCH
187DEF-EXPR-FAIL-NEXT: [[# VAR20:]]
188DEF-EXPR-FAIL-NEXT: [[# VAR42: VAR20+22]]
189DEF-EXPR-FAIL-MSG: numeric-expression.txt:[[#@LINE-1]]:21: error: {{D}}EF-EXPR-FAIL-NEXT: is not on the line after the previous match
190DEF-EXPR-FAIL-MSG-NEXT: {{D}}EF-EXPR-FAIL-NEXT: {{\[\[# VAR42: VAR20\+22\]\]}}
191DEF-EXPR-FAIL-MSG-NEXT:   {{^}}                    ^{{$}}
192
193; Verify that using a numeric variable defined on the same line (whether from
194; input or from an expression) is rejected.
195RUN: not FileCheck --check-prefix SAME-LINE-USE1 --input-file %s %s 2>&1 \
196RUN:   | FileCheck --strict-whitespace --check-prefix SAME-LINE-USE-MSG1 %s
197RUN: not FileCheck --check-prefix SAME-LINE-USE2 --input-file %s %s 2>&1 \
198RUN:   | FileCheck --strict-whitespace --check-prefix SAME-LINE-USE-MSG2 %s
199
200SAME LINE USE
2013
2024 5
203SAME-LINE-USE1-LABEL: SAME LINE USE
204SAME-LINE-USE1-NEXT: [[#]]
205SAME-LINE-USE1-NEXT: [[#VAR1:]] [[#VAR1+1]]
206SAME-LINE-USE-MSG1: numeric-expression.txt:[[#@LINE-1]]:36: error: numeric variable 'VAR1' defined earlier in the same CHECK directive
207SAME-LINE-USE-MSG1-NEXT: {{S}}AME-LINE-USE1-NEXT: {{\[\[#VAR1:\]\] \[\[#VAR1\+1\]\]}}
208SAME-LINE-USE-MSG1-NEXT:        {{^}}                                   ^{{$}}
209
210SAME-LINE-USE2-LABEL: SAME LINE USE
211SAME-LINE-USE2-NEXT: [[#VAR1:]]
212SAME-LINE-USE2-NEXT: [[#VAR2:VAR1+1]] [[#VAR2+1]]
213SAME-LINE-USE-MSG2: numeric-expression.txt:[[#@LINE-1]]:42: error: numeric variable 'VAR2' defined earlier in the same CHECK directive
214SAME-LINE-USE-MSG2-NEXT: {{S}}AME-LINE-USE2-NEXT: {{\[\[#VAR2:VAR1\+1\]\] \[\[#VAR2\+1\]\]}}
215SAME-LINE-USE-MSG2-NEXT:        {{^}}                                         ^{{$}}
216