Skip to content

Commit f4737a2

Browse files
authored
update_test_checks: keep names stable with generated functions (#87988)
Collect the original check lines in a manner that is independent of where the check lines appear in the file. This is so that we keep FileCheck variable names stable even when --include-generated-funcs is used. Reported-by: Ruiling Song <[email protected]>
1 parent a9bafe9 commit f4737a2

File tree

2 files changed

+40
-29
lines changed

2 files changed

+40
-29
lines changed

llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/stable_ir_values_funcs.ll.expected

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ define i32 @func({i32, i32} %x, i32 %y) {
1616

1717
; CHECK-LABEL: define i32 @func(
1818
; CHECK-SAME: { i32, i32 } [[X:%.*]], i32 [[Y:%.*]]) {
19-
; CHECK-NEXT: [[X_I34:%.*]] = extractvalue { i32, i32 } [[X]], 0
20-
; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[Y]], 1
21-
; CHECK-NEXT: [[TMP2:%.*]] = add i32 [[X_I34]], [[TMP1]]
22-
; CHECK-NEXT: [[TMP3:%.*]] = mul i32 [[TMP2]], 3
23-
; CHECK-NEXT: ret i32 [[TMP3]]
19+
; CHECK-NEXT: [[X_I33:%.*]] = extractvalue { i32, i32 } [[X]], 0
20+
; CHECK-NEXT: [[TMP3:%.*]] = add i32 [[Y]], 1
21+
; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[X_I33]], [[TMP3]]
22+
; CHECK-NEXT: [[TMP2:%.*]] = mul i32 [[TMP1]], 3
23+
; CHECK-NEXT: ret i32 [[TMP2]]
2424
;

llvm/utils/UpdateTestChecks/common.py

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -430,36 +430,47 @@ def collect_original_check_lines(ti: TestInfo, prefix_set: set):
430430
result[func_name][prefix] is filled with a list of right-hand-sides of check
431431
lines.
432432
"""
433-
result = {}
433+
result = collections.defaultdict(lambda: {})
434434

435+
current_prefix = None
435436
current_function = None
436437
for input_line_info in ti.ro_iterlines():
437438
input_line = input_line_info.line
438-
if current_function is not None:
439-
if input_line == "":
440-
continue
441-
if input_line.lstrip().startswith(";"):
442-
m = CHECK_RE.match(input_line)
443-
if (
444-
m is not None
445-
and m.group(1) in prefix_set
446-
and m.group(2) not in ["LABEL", "SAME"]
447-
):
448-
if m.group(1) not in current_function:
449-
current_function[m.group(1)] = []
450-
current_function[m.group(1)].append(input_line[m.end() :].strip())
451-
continue
452-
current_function = None
439+
if input_line.lstrip().startswith(";"):
440+
m = CHECK_RE.match(input_line)
441+
if m is not None:
442+
prefix = m.group(1)
443+
check_kind = m.group(2)
444+
line = input_line[m.end() :].strip()
445+
446+
if prefix != current_prefix:
447+
current_function = None
448+
current_prefix = None
449+
450+
if check_kind not in ["LABEL", "SAME"]:
451+
if current_function is not None:
452+
current_function.append(line)
453+
continue
453454

454-
m = IR_FUNCTION_RE.match(input_line)
455-
if m is not None:
456-
func_name = m.group(1)
457-
if ti.args.function is not None and func_name != ti.args.function:
458-
# When filtering on a specific function, skip all others.
459-
continue
455+
if check_kind == "SAME":
456+
continue
457+
458+
if check_kind == "LABEL":
459+
m = IR_FUNCTION_RE.match(line)
460+
if m is not None:
461+
func_name = m.group(1)
462+
if (
463+
ti.args.function is not None
464+
and func_name != ti.args.function
465+
):
466+
# When filtering on a specific function, skip all others.
467+
continue
468+
469+
current_prefix = prefix
470+
current_function = result[func_name][prefix] = []
471+
continue
460472

461-
assert func_name not in result
462-
current_function = result[func_name] = {}
473+
current_function = None
463474

464475
return result
465476

0 commit comments

Comments
 (0)