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 with default matching format without spaces.
6DEF DEFAULT FMT NO SPC  // CHECK-LABEL: DEF DEFAULT FMT NO SPC
710  // CHECK-NEXT: {{^}}[[#UNSI:]]
8
9; Numeric variable definition with default matching format with different
10; spacing.
11DEF DEFAULT FMT SPC  // CHECK-LABEL: DEF DEFAULT FMT SPC
1211  // CHECK-NEXT: {{^}}[[# UNSIa:]]
1311  // CHECK-NEXT: {{^}}[[# UNSIb :]]
1411  // CHECK-NEXT: {{^}}[[# UNSIc : ]]
15
16; Numeric variable redefinition.
17REDEF NO SPC  // CHECK-LABEL: REDEF
1811  // CHECK-NEXT: {{^}}[[#UNSI:]]
19
20; Numeric variable definition with explicit matching format.
21DEF FMT  // CHECK-LABEL: DEF FMT
22c  // CHECK-NEXT: {{^}}[[#%x,LHEX:]]
23D  // CHECK-NEXT: {{^}}[[#%X,UHEX:]]
24
25; Numeric variable definition with explicit matching format with different
26; spacing.
27DEF FMT SPC  // CHECK-LABEL: DEF FMT SPC
28c  // CHECK-NEXT: {{^}}[[# %x , LHEXa : ]]
29
30; Numeric variable definition with unsupported matching format.
31RUN: %ProtectFileCheckOutput \
32RUN: not FileCheck --check-prefixes ERR,INVALID-FMT-SPEC1 --input-file %s %s 2>&1 \
33RUN:   | FileCheck --check-prefix INVALID-FMT-SPEC-MSG1 --strict-whitespace %s
34RUN: %ProtectFileCheckOutput \
35RUN: not FileCheck --check-prefixes ERR,INVALID-FMT-SPEC2 --input-file %s %s 2>&1 \
36RUN:   | FileCheck --check-prefix INVALID-FMT-SPEC-MSG2 --strict-whitespace %s
37
38DEF INVALID FMT
39INVVAR1=a
40INVVAR2=11
41ERR-LABEL: DEF INVALID FMT
42INVALID-FMT-SPEC1-NEXT: INVVAR1=[[#%c,INVVAR1:]]
43INVALID-FMT-SPEC2-NEXT: INVVAR2=[[#%hhd,INVVAR2:]]
44INVALID-FMT-SPEC-MSG1: numeric-expression.txt:[[#@LINE-2]]:37: error: invalid format specifier in expression
45INVALID-FMT-SPEC-MSG1-NEXT: {{I}}NVALID-FMT-SPEC1-NEXT: INVVAR1={{\[\[#%c,INVVAR1:\]\]}}
46INVALID-FMT-SPEC-MSG1-NEXT:    {{^}}                                    ^{{$}}
47INVALID-FMT-SPEC-MSG2: numeric-expression.txt:[[#@LINE-4]]:37: error: invalid format specifier in expression
48INVALID-FMT-SPEC-MSG2-NEXT: {{I}}NVALID-FMT-SPEC2-NEXT: INVVAR2={{\[\[#%hhd,INVVAR2:\]\]}}
49INVALID-FMT-SPEC-MSG2-NEXT:    {{^}}                                    ^{{$}}
50
51; Numeric expressions in explicit matching format and default matching rule using
52; variables defined on other lines without spaces.
53USE EXPL FMT IMPL MATCH  // CHECK-LABEL: USE EXPL FMT IMPL MATCH
5411  // CHECK-NEXT: {{^}}[[#%u,UNSI]]
5512  // CHECK-NEXT: {{^}}[[#%u,UNSI+1]]
5610  // CHECK-NEXT: {{^}}[[#%u,UNSI-1]]
57c   // CHECK-NEXT: {{^}}[[#%x,LHEX]]
58d   // CHECK-NEXT: {{^}}[[#%x,LHEX+1]]
59b   // CHECK-NEXT: {{^}}[[#%x,LHEX-1]]
601a  // CHECK-NEXT: {{^}}[[#%x,LHEX+0xe]]
611a  // CHECK-NEXT: {{^}}[[#%x,LHEX+0xE]]
62D   // CHECK-NEXT: {{^}}[[#%X,UHEX]]
63E   // CHECK-NEXT: {{^}}[[#%X,UHEX+1]]
64C   // CHECK-NEXT: {{^}}[[#%X,UHEX-1]]
651B  // CHECK-NEXT: {{^}}[[#%X,UHEX+0xe]]
661B  // CHECK-NEXT: {{^}}[[#%X,UHEX+0xE]]
6711  // CHECK-NEXT: {{^}}[[#%u,UNSIa]]
6811  // CHECK-NEXT: {{^}}[[#%u,UNSIb]]
6911  // CHECK-NEXT: {{^}}[[#%u,UNSIc]]
70c   // CHECK-NEXT: {{^}}[[#%x,LHEXa]]
71
72; Numeric expressions in explicit matching format and default matching rule using
73; variables defined on other lines with different spacing.
74USE EXPL FMT IMPL MATCH SPC  // CHECK-LABEL: USE EXPL FMT IMPL MATCH SPC
7511  // CHECK-NEXT: {{^}}[[#%u, UNSI]]
7611  // CHECK-NEXT: {{^}}[[# %u, UNSI]]
7711  // CHECK-NEXT: {{^}}[[# %u, UNSI ]]
7812  // CHECK-NEXT: {{^}}[[#%u, UNSI+1]]
7912  // CHECK-NEXT: {{^}}[[# %u, UNSI+1]]
8012  // CHECK-NEXT: {{^}}[[# %u , UNSI+1]]
8112  // CHECK-NEXT: {{^}}[[# %u , UNSI +1]]
8212  // CHECK-NEXT: {{^}}[[# %u , UNSI + 1]]
8312  // CHECK-NEXT: {{^}}[[# %u , UNSI + 1 ]]
8410  // CHECK-NEXT: {{^}}[[#%u, UNSI-1]]
8510  // CHECK-NEXT: {{^}}[[# %u, UNSI-1]]
8610  // CHECK-NEXT: {{^}}[[# %u , UNSI-1]]
8710  // CHECK-NEXT: {{^}}[[# %u , UNSI -1]]
8810  // CHECK-NEXT: {{^}}[[# %u , UNSI - 1]]
8910  // CHECK-NEXT: {{^}}[[# %u , UNSI - 1 ]]
90
91; Numeric expressions in implicit matching format and default matching rule using
92; variables defined on other lines.
93USE IMPL FMT IMPL MATCH  // CHECK-LABEL: USE IMPL FMT IMPL MATCH
9411  // CHECK-NEXT: {{^}}[[#UNSI]]
9512  // CHECK-NEXT: {{^}}[[#UNSI+1]]
9610  // CHECK-NEXT: {{^}}[[#UNSI-1]]
97c   // CHECK-NEXT: {{^}}[[#LHEX]]
98d   // CHECK-NEXT: {{^}}[[#LHEX+1]]
99b   // CHECK-NEXT: {{^}}[[#LHEX-1]]
1001a  // CHECK-NEXT: {{^}}[[#LHEX+0xe]]
1011a  // CHECK-NEXT: {{^}}[[#LHEX+0xE]]
102D   // CHECK-NEXT: {{^}}[[#UHEX]]
103E   // CHECK-NEXT: {{^}}[[#UHEX+1]]
104C   // CHECK-NEXT: {{^}}[[#UHEX-1]]
1051B  // CHECK-NEXT: {{^}}[[#UHEX+0xe]]
1061B  // CHECK-NEXT: {{^}}[[#UHEX+0xE]]
107
108; Numeric expressions using variables defined on other lines and an immediate
109; interpreted as an unsigned value.
110; Note: 9223372036854775819 = 0x8000000000000000 + 11
111USE IMPL FMT IMPL MATCH UNSIGNED IMM
1129223372036854775819
113CHECK-LABEL: USE IMPL FMT IMPL MATCH UNSIGNED IMM
114CHECK-NEXT: [[#UNSI+0x8000000000000000]]
115
116; Numeric expressions with matching format overriding the implicit format of
117; variables defined on other lines.
118USE CONV FMT IMPL MATCH  // CHECK-LABEL: USE CONV FMT IMPL MATCH
119b   // CHECK-NEXT: {{^}}[[# %x, UNSI]]
120B   // CHECK-NEXT: {{^}}[[# %X, UNSI]]
12112  // CHECK-NEXT: {{^}}[[# %u, LHEX]]
122C   // CHECK-NEXT: {{^}}[[# %X, LHEX]]
12313  // CHECK-NEXT: {{^}}[[# %u, UHEX]]
124d   // CHECK-NEXT: {{^}}[[# %x, UHEX]]
125
126; Conflicting implicit format.
127RUN: %ProtectFileCheckOutput \
128RUN: not FileCheck --check-prefixes CHECK,FMT-CONFLICT1 --input-file %s %s 2>&1 \
129RUN:   | FileCheck --strict-whitespace --check-prefix FMT-CONFLICT1-MSG %s
130RUN: %ProtectFileCheckOutput \
131RUN: not FileCheck --check-prefixes CHECK,FMT-CONFLICT2 --input-file %s %s 2>&1 \
132RUN:   | FileCheck --strict-whitespace --check-prefix FMT-CONFLICT2-MSG %s
133
134VAR USE IMPL FMT CONFLICT
13523
136FMT-CONFLICT1-LABEL: VAR USE IMPL FMT CONFLICT
137FMT-CONFLICT1-NEXT: [[#UNSI + LHEX]]
138FMT-CONFLICT1-MSG: numeric-expression.txt:[[#@LINE-1]]:24: error: implicit format conflict between 'UNSI' (%u) and 'LHEX' (%x), need an explicit format specifier
139FMT-CONFLICT1-MSG-NEXT: {{F}}MT-CONFLICT1-NEXT: {{\[\[#UNSI \+ LHEX\]\]}}
140FMT-CONFLICT1-MSG-NEXT: {{^                       \^$}}
141
142VAR USE IMPL FMT CONFLICT COMPLEX
14334
144FMT-CONFLICT2-LABEL: VAR USE IMPL FMT CONFLICT
145FMT-CONFLICT2-NEXT: [[#UNSI + UNSIa + LHEX]]
146FMT-CONFLICT2-MSG: numeric-expression.txt:[[#@LINE-1]]:24: error: implicit format conflict between 'UNSI + UNSIa' (%u) and 'LHEX' (%x), need an explicit format specifier
147FMT-CONFLICT2-MSG-NEXT: {{F}}MT-CONFLICT2-NEXT: {{\[\[#UNSI \+ UNSIa \+ LHEX\]\]}}
148FMT-CONFLICT2-MSG-NEXT: {{^                       \^$}}
149
150; Explicitly specified format can override conflicting implicit formats.
151VAR USE IMPL OVERRIDE FMT CONFLICT  // CHECK-LABEL: VAR USE IMPL OVERRIDE FMT CONFLICT
15223  // CHECK-NEXT: {{^}}[[# %u, UNSI + LHEX]]
153
154; Numeric expressions using more than one variable defined on other lines.
155USE MULTI VAR  // CHECK-LABEL: USE MULTI VAR
15622  // CHECK-NEXT: {{^}}[[#UNSI+UNSIa]]
157
158; Numeric expression using a variable defined from a numeric expression.
159DEF EXPR GOOD MATCH  // CHECK-LABEL: DEF EXPR GOOD MATCH
16042  // CHECK-NEXT: {{^}}[[# VAR42:UNSI+31]]
16141  // CHECK-NEXT: {{^}}[[# VAR42-1]]
162
163; Empty numeric expression.
164EMPTY NUM EXPR  // CHECK-LABEL: EMPTY NUM EXPR
165foo 104 bar  // CHECK-NEXT: {{^}}foo [[#]] bar
166
167; Numeric expression using undefined variables.
168RUN: %ProtectFileCheckOutput \
169RUN: not FileCheck --check-prefix UNDEF-USE --input-file %s %s 2>&1 \
170RUN:   | FileCheck --strict-whitespace --check-prefix UNDEF-USE-MSG %s
171
172UNDEF VAR USE
173UNDEFVAR: 11
174UNDEF-USE-LABEL: UNDEF VAR USE
175UNDEF-USE-NEXT: UNDEFVAR: [[#UNDEFVAR1+UNDEFVAR2]]
176UNDEF-USE-MSG: numeric-expression.txt:[[#@LINE-1]]:17: error: {{U}}NDEF-USE-NEXT: expected string not found in input
177UNDEF-USE-MSG-NEXT:      {{U}}NDEF-USE-NEXT: UNDEFVAR: {{\[\[#UNDEFVAR1\+UNDEFVAR2\]\]}}
178UNDEF-USE-MSG-NEXT:     {{^}}                ^{{$}}
179UNDEF-USE-MSG-NEXT:      numeric-expression.txt:[[#@LINE-6]]:1: note: scanning from here
180UNDEF-USE-MSG-NEXT:      UNDEFVAR: 11
181UNDEF-USE-MSG-NEXT: {{^}}^{{$}}
182UNDEF-USE-MSG-NEXT:      numeric-expression.txt:[[#@LINE-9]]:1: note: uses undefined variable(s): "UNDEFVAR1" "UNDEFVAR2"
183UNDEF-USE-MSG-NEXT:      UNDEFVAR: 11
184UNDEF-USE-MSG-NEXT: {{^}}^{{$}}
185
186; Numeric expression with unsupported operator.
187RUN: %ProtectFileCheckOutput \
188RUN: not FileCheck -D#NUMVAR=10 --check-prefix INVAL-OP \
189RUN:               --input-file %s %s 2>&1 \
190RUN:   | FileCheck --strict-whitespace --check-prefix INVAL-OP-MSG %s
191
192INVALID OPERATOR
193NUMVAR*2: 22
194INVAL-OP-LABEL: INVALID OPERATOR
195INVAL-OP-NEXT: NUMVAR*2: [[#NUMVAR*2]]
196INVAL-OP-MSG: numeric-expression.txt:[[#@LINE-1]]:35: error: unsupported operation '*'
197INVAL-OP-MSG-NEXT: {{I}}NVAL-OP-NEXT: NUMVAR*2: {{\[\[#NUMVAR\*2\]\]}}
198INVAL-OP-MSG-NEXT:     {{^}}                                  ^{{$}}
199
200; Name conflict between Numeric variable definition and string variable
201; definition whether from the command-line or input text.
202RUN: %ProtectFileCheckOutput \
203RUN: not FileCheck --check-prefixes CONFLICT,CONFLICT1,CONFLICT2 \
204RUN:               --input-file %s %s 2>&1 \
205RUN:   | FileCheck --strict-whitespace --check-prefix INPUT-STR-CONFLICT %s
206RUN: %ProtectFileCheckOutput \
207RUN: not FileCheck -D#NUMVAR=42 --check-prefixes CONFLICT,CONFLICT2 \
208RUN:               --input-file %s %s 2>&1 \
209RUN:   | FileCheck --strict-whitespace --check-prefix INPUT-STR-CONFLICT %s
210RUN: %ProtectFileCheckOutput \
211RUN: not FileCheck -D#NUMVAR=42 -DNUMVAR=foobar --check-prefix CONFLICT \
212RUN:               --input-file %s %s 2>&1 \
213RUN:   | FileCheck --strict-whitespace --check-prefix CLI-STR-CONFLICT %s
214RUN: %ProtectFileCheckOutput \
215RUN: not FileCheck --check-prefixes CONFLICT,CONFLICT3,CONFLICT4 \
216RUN:               --input-file %s %s 2>&1 \
217RUN:   | FileCheck --strict-whitespace --check-prefix INPUT-NUM-CONFLICT %s
218RUN: %ProtectFileCheckOutput \
219RUN: not FileCheck -DSTRVAR=foobar --check-prefixes CONFLICT,CONFLICT4 \
220RUN:               --input-file %s %s 2>&1 \
221RUN:   | FileCheck --strict-whitespace --check-prefix INPUT-NUM-CONFLICT %s
222RUN: %ProtectFileCheckOutput \
223RUN: not FileCheck -DSTRVAR=foobar -D#STRVAR=42 --check-prefix CONFLICT \
224RUN:               --input-file %s %s 2>&1 \
225RUN:   | FileCheck --strict-whitespace --check-prefix CLI-NUM-CONFLICT %s
226
227STRVAR NUMVAR CONFLICT
228redef1 42
229foobar
230redef2 42
231CONFLICT-LABEL: STRVAR NUMVAR CONFLICT
232CONFLICT1-NEXT: redef1 [[#NUMVAR:]]
233CONFLICT2: [[NUMVAR:foo.*]]
234CONFLICT3: [[STRVAR:foo.*]]
235CONFLICT4: redef2 [[#STRVAR:]]
236INPUT-STR-CONFLICT: numeric-expression.txt:[[#@LINE-3]]:14: error: numeric variable with name 'NUMVAR' already exists
237INPUT-STR-CONFLICT-NEXT: {{C}}ONFLICT2: {{\[\[NUMVAR:foo\.\*\]\]}}
238INPUT-STR-CONFLICT-NEXT:    {{^}}             ^{{$}}
239CLI-STR-CONFLICT: Global defines:2:19: error: numeric variable with name 'NUMVAR' already exists
240CLI-STR-CONFLICT-NEXT:      Global define #2: NUMVAR=foobar
241CLI-STR-CONFLICT-NEXT: {{^}}                  ^{{$}}
242INPUT-NUM-CONFLICT: numeric-expression.txt:[[#@LINE-7]]:22: error: string variable with name 'STRVAR' already exists
243 INPUT-NUM-CONFLICT-NEXT: CONFLICT4: redef2 {{\[\[#STRVAR:\]\]}}
244INPUT-NUM-CONFLICT-NEXT: {{^}}                     ^{{$}}
245CLI-NUM-CONFLICT: Global defines:2:45: error: string variable with name 'STRVAR' already exists
246 CLI-NUM-CONFLICT-NEXT: Global define #2: #STRVAR=42 (parsed as: {{\[\[#STRVAR:42\]\]}})
247CLI-NUM-CONFLICT-NEXT: {{^}}                                            ^{{$}}
248
249; Numeric variable definition with too big value.
250RUN: %ProtectFileCheckOutput \
251RUN: not FileCheck --check-prefix BIGVAL --input-file %s %s 2>&1 \
252RUN:   | FileCheck --strict-whitespace --check-prefix BIGVAL-MSG %s
253
254BIG VALUE
255NUMVAR: 10000000000000000000000
256BIGVAL-LABEL: BIG VALUE
257BIGVAL-NEXT: NUMVAR: [[#NUMVAR:]]
258BIGVAL-MSG: numeric-expression.txt:[[#@LINE-3]]:9: error: unable to represent numeric value
259 BIGVAL-MSG-NEXT: {{N}}UMVAR: 10000000000000000000000
260BIGVAL-MSG-NEXT: {{^}}        ^{{$}}
261
262; Verify that when a variable is set to an expression the expression is still
263; checked.
264RUN: %ProtectFileCheckOutput \
265RUN: not FileCheck --check-prefix DEF-EXPR-FAIL --input-file %s %s 2>&1 \
266RUN:   | FileCheck --strict-whitespace --check-prefix DEF-EXPR-FAIL-MSG %s
267
268DEF EXPR WRONG MATCH
26920
27043
271DEF-EXPR-FAIL-LABEL: DEF EXPR WRONG MATCH
272DEF-EXPR-FAIL-NEXT: [[# VAR20:]]
273DEF-EXPR-FAIL-NEXT: [[# VAR42: VAR20+22]]
274DEF-EXPR-FAIL-MSG: numeric-expression.txt:[[#@LINE-1]]:21: error: {{D}}EF-EXPR-FAIL-NEXT: is not on the line after the previous match
275DEF-EXPR-FAIL-MSG-NEXT: {{D}}EF-EXPR-FAIL-NEXT: {{\[\[# VAR42: VAR20\+22\]\]}}
276DEF-EXPR-FAIL-MSG-NEXT:   {{^}}                    ^{{$}}
277
278; Verify that using a numeric variable defined on the same line (whether from
279; input or from an expression) is rejected.
280RUN: %ProtectFileCheckOutput \
281RUN: not FileCheck --check-prefix SAME-LINE-USE1 --input-file %s %s 2>&1 \
282RUN:   | FileCheck --strict-whitespace --check-prefix SAME-LINE-USE-MSG1 %s
283RUN: %ProtectFileCheckOutput \
284RUN: not FileCheck --check-prefix SAME-LINE-USE2 --input-file %s %s 2>&1 \
285RUN:   | FileCheck --strict-whitespace --check-prefix SAME-LINE-USE-MSG2 %s
286
287SAME LINE USE
2883
2894 5
290SAME-LINE-USE1-LABEL: SAME LINE USE
291SAME-LINE-USE1-NEXT: [[#]]
292SAME-LINE-USE1-NEXT: [[#UNSI:]] [[#UNSI+1]]
293SAME-LINE-USE-MSG1: numeric-expression.txt:[[#@LINE-1]]:36: error: numeric variable 'UNSI' defined earlier in the same CHECK directive
294SAME-LINE-USE-MSG1-NEXT: {{S}}AME-LINE-USE1-NEXT: {{\[\[#UNSI:\]\] \[\[#UNSI\+1\]\]}}
295SAME-LINE-USE-MSG1-NEXT:        {{^}}                                   ^{{$}}
296
297SAME-LINE-USE2-LABEL: SAME LINE USE
298SAME-LINE-USE2-NEXT: [[#UNSI:]]
299SAME-LINE-USE2-NEXT: [[#UNSI2:UNSI+1]] [[#UNSI2+1]]
300SAME-LINE-USE-MSG2: numeric-expression.txt:[[#@LINE-1]]:43: error: numeric variable 'UNSI2' defined earlier in the same CHECK directive
301SAME-LINE-USE-MSG2-NEXT: {{S}}AME-LINE-USE2-NEXT: {{\[\[#UNSI2:UNSI\+1\]\] \[\[#UNSI2\+1\]\]}}
302SAME-LINE-USE-MSG2-NEXT:        {{^}}                                          ^{{$}}
303
304; Invalid change of format in variable redefinition.
305RUN: %ProtectFileCheckOutput \
306RUN: not FileCheck --check-prefix REDEF-NEW-FMT --input-file %s %s 2>&1 \
307RUN:   | FileCheck --strict-whitespace --check-prefix REDEF-NEW-FMT-MSG %s
308
309VAR REDEF FMT CHANGE
31022
311DC
312REDEF-NEW-FMT-LABEL: VAR REDEF FMT CHANGE
313REDEF-NEW-FMT-NEXT: [[#UNSI:]]
314REDEF-NEW-FMT-NEXT: [[#%X,UNSI:]]
315REDEF-NEW-FMT-MSG: numeric-expression.txt:[[#@LINE-1]]:31: error: format different from previous variable definition
316REDEF-NEW-FMT-MSG-NEXT: {{R}}EDEF-NEW-FMT-NEXT: {{\[\[#%X,UNSI:\]\]}}
317REDEF-NEW-FMT-MSG-NEXT:    {{^}}                              ^{{$}}
318