diff options
| author | Kunqiu Chen <camsyn@foxmail.com> | 2025-11-01 17:01:30 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-01 17:01:30 +0800 |
| commit | 82cf54fbf6a7cd185cfe2279ca9d0cf4c4ea16e0 (patch) | |
| tree | a7542644af525b24b681f6f48a8ab230bcff9127 /llvm/utils/UpdateTestChecks/common.py | |
| parent | c07440b8879c61c1c388499278197ce6970f2472 (diff) | |
| download | llvm-82cf54fbf6a7cd185cfe2279ca9d0cf4c4ea16e0.zip llvm-82cf54fbf6a7cd185cfe2279ca9d0cf4c4ea16e0.tar.gz llvm-82cf54fbf6a7cd185cfe2279ca9d0cf4c4ea16e0.tar.bz2 | |
[UTC] CHECK-EMPTY instead of skipping blank lines (#165718)
Previously, any blank lines in IR were ignored by UTC, leading to more
fragile `CHECK`s being generated.
This change lets UTC, 1) emit `CHECK-EMPTY` to check blank lines, and 2)
generate more `CHECK-NEXT`s, landing the discussion
https://github.com/llvm/llvm-project/pull/165419#issuecomment-3457572422.
Moreover, this change also aligns the behavior of IR check-gen to ASM
check-gen, which has been emitting `CHECK-EMPTY` since
https://github.com/llvm/llvm-project/commit/a8a89c77ea3c16b45763fca6940bbfd3bef7884f.
Diffstat (limited to 'llvm/utils/UpdateTestChecks/common.py')
| -rw-r--r-- | llvm/utils/UpdateTestChecks/common.py | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py index 119303c..2dad16a 100644 --- a/llvm/utils/UpdateTestChecks/common.py +++ b/llvm/utils/UpdateTestChecks/common.py @@ -29,7 +29,7 @@ Version changelog: 'none' and 'all'. 'smart' is the default. 5: Basic block labels are matched by FileCheck expressions 6: The semantics of TBAA checks has been incorporated in the check lines. -7: Indent switch-cases correctly. +7: Indent switch-cases correctly; CHECK-EMPTY instead of skipping blank lines. """ DEFAULT_VERSION = 6 @@ -2280,6 +2280,14 @@ def add_checks( # For IR output, change all defs to FileCheck variables, so we're immune # to variable naming fashions. else: + if ginfo.get_version() >= 7: + # Record the indices of blank lines in the function body preemptively. + blank_line_indices = { + i for i, line in enumerate(func_body) if line.strip() == "" + } + else: + blank_line_indices = set() + func_body = generalize_check_lines( func_body, ginfo, @@ -2305,9 +2313,18 @@ def add_checks( is_blank_line = False - for func_line in func_body: + for idx, func_line in enumerate(func_body): if func_line.strip() == "": - is_blank_line = True + # We should distinguish if the line is a 'fake' blank line generated by + # generalize_check_lines removing comments. + # Fortunately, generalize_check_lines does not change the index of each line, + # we can record the indices of blank lines preemptively. + if idx in blank_line_indices: + output_lines.append( + "{} {}-EMPTY:".format(comment_marker, checkprefix) + ) + else: + is_blank_line = True continue if not check_inst_comments: # Do not waste time checking IR comments unless necessary. |
