Skip to content

Commit cc675c6

Browse files
authored
[utils] Use stricter SSA regexp for CHECK-SAME. (#128083)
When CHECK-SAME checks are split across multiple lines, the '.*' regexp for the SSA variable name may cause problems, e.g.: ``` // CHECK_LABEL: func.func @whatever( // CHECK-SAME: %[[VAL_0:.*]]: i32, // CHECK-SAME: %[[VAL_1:.*]]: i32, // CHECK-SAME: %[[VAL_2:.*]]: i64) ``` This will not work for `func.func @whatever(%0: i32, %1: i32, %2: i64)`, because VAL_0 will match to `0: i32, %1`.
1 parent cc46d00 commit cc675c6

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

mlir/utils/generate-test-checks.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def get_num_ssa_results(input_line):
159159

160160

161161
# Process a line of input that has been split at each SSA identifier '%'.
162-
def process_line(line_chunks, variable_namer):
162+
def process_line(line_chunks, variable_namer, strict_name_re=False):
163163
output_line = ""
164164

165165
# Process the rest that contained an SSA value name.
@@ -180,7 +180,14 @@ def process_line(line_chunks, variable_namer):
180180
else:
181181
# Otherwise, generate a new variable.
182182
variable = variable_namer.generate_name(ssa_name)
183-
output_line += "%[[" + variable + ":.*]]"
183+
if strict_name_re:
184+
# Use stricter regexp for the variable name, if requested.
185+
# Greedy matching may cause issues with the generic '.*'
186+
# regexp when the checks are split across several
187+
# lines (e.g. for CHECK-SAME).
188+
output_line += "%[[" + variable + ":" + SSA_RE_STR + "]]"
189+
else:
190+
output_line += "%[[" + variable + ":.*]]"
184191

185192
# Append the non named group.
186193
output_line += chunk[len(ssa_name) :]
@@ -390,7 +397,9 @@ def main():
390397
output_line += " " * len(ssa_split[0])
391398

392399
# Process the rest of the line.
393-
output_line += process_line([argument], variable_namer)
400+
output_line += process_line(
401+
[argument], variable_namer, strict_name_re=True
402+
)
394403

395404
# Append the output line.
396405
output_segments[-1].append(output_line)

0 commit comments

Comments
 (0)