Skip to content

Conversation

@Camsyn
Copy link
Contributor

@Camsyn Camsyn commented Oct 27, 2025

LLVM prints switch cases indented by 2 additional spaces, as follows:

  switch i32 %x, label %default [
    i32 0, label %phi
    i32 1, label %phi
  ]

Since this only changes the output IR of update_test_checks.py and does not change the logic of the File Check Pattern, there seems to be no need to update the existing test cases.

@llvmbot
Copy link
Member

llvmbot commented Oct 27, 2025

@llvm/pr-subscribers-testing-tools

Author: Kunqiu Chen (Camsyn)

Changes

LLVM prints switch cases indented by 2 additional spaces, as follows:

  switch i32 %x, label %default [
    i32 0, label %phi
    i32 1, label %phi
  ]

Since this only changes the output IR of update_test_checks.py and does not change the logic of the File Check Pattern, there seems to be no need to update the existing test cases.


Full diff: https://github.com/llvm/llvm-project/pull/165212.diff

2 Files Affected:

  • (modified) llvm/utils/UpdateTestChecks/common.py (+1)
  • (modified) llvm/utils/update_test_checks.py (+7-2)
diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py
index a5e3c39bfdecd..1ba716112f527 100644
--- a/llvm/utils/UpdateTestChecks/common.py
+++ b/llvm/utils/UpdateTestChecks/common.py
@@ -606,6 +606,7 @@ def invoke_tool(exe, cmd_args, ir, preprocess_cmd=None, verbose=False):
 DEBUG_ONLY_ARG_RE = re.compile(r"-debug-only[= ]([^ ]+)")
 
 IS_DEBUG_RECORD_RE = re.compile(r"^(\s+)#dbg_")
+IS_SWITCH_CASE_RE = re.compile(r"^\s+i\d{1,2} \d+, label %\w+")
 
 SCRUB_LEADING_WHITESPACE_RE = re.compile(r"^(\s+)")
 SCRUB_WHITESPACE_RE = re.compile(r"(?!^(|  \w))[ \t]+", flags=re.M)
diff --git a/llvm/utils/update_test_checks.py b/llvm/utils/update_test_checks.py
index 3b562fbc54f78..37d046e53aa82 100755
--- a/llvm/utils/update_test_checks.py
+++ b/llvm/utils/update_test_checks.py
@@ -260,9 +260,14 @@ def update_test(ti: common.TestInfo):
                 skip_same_checks=dropped_previous_line,
             ):
                 # This input line of the function body will go as-is into the output.
-                # Except make leading whitespace uniform: 2 spaces. 4 for debug records.
+                # Except make leading whitespace uniform: 2 spaces. 4 for debug records/switch cases.
                 indent = (
-                    "  " if not common.IS_DEBUG_RECORD_RE.match(input_line) else "    "
+                    " " * 4
+                    if (
+                        common.IS_DEBUG_RECORD_RE.match(input_line)
+                        or common.IS_SWITCH_CASE_RE.match(input_line)
+                    )
+                    else " " * 2
                 )
                 input_line = common.SCRUB_LEADING_WHITESPACE_RE.sub(indent, input_line)
                 output_lines.append(input_line)

@Camsyn Camsyn changed the title [UTC][NFC] Indent switch cases [UTC] Indent switch cases Oct 27, 2025
Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have a UTC test for this (see llvm/test/tools/UpdateTestChecks/).

I'd also consider gating this under a new UTC version. I think this will produce just enough test churn to be annoying.

" " * 4
if (
common.IS_DEBUG_RECORD_RE.match(input_line)
or common.IS_SWITCH_CASE_RE.match(input_line)
Copy link
Contributor Author

@Camsyn Camsyn Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also consider gating this under a new UTC version. I think this will produce just enough test churn to be annoying.

Do you mean some change like this?

Suggested change
or common.IS_SWITCH_CASE_RE.match(input_line)
or (
ti.args.version > 4
and common.IS_SWITCH_CASE_RE.match(input_line)
)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, though it would be > 6, see

6: The semantics of TBAA checks has been incorporated in the check lines.
.

@Camsyn Camsyn force-pushed the fix-update-test-checks branch from 144da61 to a9da88c Compare October 27, 2025 12:24
@Camsyn Camsyn requested a review from nikic October 27, 2025 12:47
@Camsyn Camsyn force-pushed the fix-update-test-checks branch from d9b16c3 to 01b0ca9 Compare October 28, 2025 08:40
Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Camsyn Camsyn merged commit 566c731 into llvm:main Oct 28, 2025
13 of 14 checks passed
Lukacma pushed a commit to Lukacma/llvm-project that referenced this pull request Oct 29, 2025
LLVM prints switch cases indented by 2 additional spaces, as follows:
```LLVM
  switch i32 %x, label %default [
    i32 0, label %phi
    i32 1, label %phi
  ]
```

Since this only changes the output IR of update_test_checks.py and does
not change the logic of the File Check Pattern, there seems to be no
need to update the existing test cases.
aokblast pushed a commit to aokblast/llvm-project that referenced this pull request Oct 30, 2025
LLVM prints switch cases indented by 2 additional spaces, as follows:
```LLVM
  switch i32 %x, label %default [
    i32 0, label %phi
    i32 1, label %phi
  ]
```

Since this only changes the output IR of update_test_checks.py and does
not change the logic of the File Check Pattern, there seems to be no
need to update the existing test cases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants