Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
; RUN: opt < %s -S | FileCheck %s

; Test whether the UTC format the switch-cases correctly, which requires TWO extra spaces.

define i8 @testi8(i8 %x) {
switch i8 %x, label %default [
i8 0, label %case1
i8 1, label %case2
i8 2, label %case3
i8 3, label %case3
]
default:
ret i8 0
case1:
ret i8 1
case2:
ret i8 2
case3:
ret i8 3
}

define i32 @testi32(i32 %x) {
switch i32 %x, label %default [
i32 0, label %case1
i32 1, label %case2
i32 2, label %case3
i32 3, label %case3
]
default:
ret i32 0
case1:
ret i32 1
case2:
ret i32 2
case3:
ret i32 3
}

define i128 @testi128(i128 %x) {
switch i128 %x, label %default [
i128 0, label %case1
i128 1, label %case2
i128 2, label %case3
i128 3, label %case3
]
default:
ret i128 0
case1:
ret i128 1
case2:
ret i128 2
case3:
ret i128 3
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 7
; RUN: opt < %s -S | FileCheck %s

; Test whether the UTC format the switch-cases correctly, which requires TWO extra spaces.

define i8 @testi8(i8 %x) {
; CHECK-LABEL: define i8 @testi8(
; CHECK-SAME: i8 [[X:%.*]]) {
; CHECK-NEXT: switch i8 [[X]], label %[[DEFAULT:.*]] [
; CHECK-NEXT: i8 0, label %[[CASE1:.*]]
; CHECK-NEXT: i8 1, label %[[CASE2:.*]]
; CHECK-NEXT: i8 2, label %[[CASE3:.*]]
; CHECK-NEXT: i8 3, label %[[CASE3]]
; CHECK-NEXT: ]
; CHECK: [[DEFAULT]]:
; CHECK-NEXT: ret i8 0
; CHECK: [[CASE1]]:
; CHECK-NEXT: ret i8 1
; CHECK: [[CASE2]]:
; CHECK-NEXT: ret i8 2
; CHECK: [[CASE3]]:
; CHECK-NEXT: ret i8 3
;
switch i8 %x, label %default [
i8 0, label %case1
i8 1, label %case2
i8 2, label %case3
i8 3, label %case3
]
default:
ret i8 0
case1:
ret i8 1
case2:
ret i8 2
case3:
ret i8 3
}

define i32 @testi32(i32 %x) {
; CHECK-LABEL: define i32 @testi32(
; CHECK-SAME: i32 [[X:%.*]]) {
; CHECK-NEXT: switch i32 [[X]], label %[[DEFAULT:.*]] [
; CHECK-NEXT: i32 0, label %[[CASE1:.*]]
; CHECK-NEXT: i32 1, label %[[CASE2:.*]]
; CHECK-NEXT: i32 2, label %[[CASE3:.*]]
; CHECK-NEXT: i32 3, label %[[CASE3]]
; CHECK-NEXT: ]
; CHECK: [[DEFAULT]]:
; CHECK-NEXT: ret i32 0
; CHECK: [[CASE1]]:
; CHECK-NEXT: ret i32 1
; CHECK: [[CASE2]]:
; CHECK-NEXT: ret i32 2
; CHECK: [[CASE3]]:
; CHECK-NEXT: ret i32 3
;
switch i32 %x, label %default [
i32 0, label %case1
i32 1, label %case2
i32 2, label %case3
i32 3, label %case3
]
default:
ret i32 0
case1:
ret i32 1
case2:
ret i32 2
case3:
ret i32 3
}

define i128 @testi128(i128 %x) {
; CHECK-LABEL: define i128 @testi128(
; CHECK-SAME: i128 [[X:%.*]]) {
; CHECK-NEXT: switch i128 [[X]], label %[[DEFAULT:.*]] [
; CHECK-NEXT: i128 0, label %[[CASE1:.*]]
; CHECK-NEXT: i128 1, label %[[CASE2:.*]]
; CHECK-NEXT: i128 2, label %[[CASE3:.*]]
; CHECK-NEXT: i128 3, label %[[CASE3]]
; CHECK-NEXT: ]
; CHECK: [[DEFAULT]]:
; CHECK-NEXT: ret i128 0
; CHECK: [[CASE1]]:
; CHECK-NEXT: ret i128 1
; CHECK: [[CASE2]]:
; CHECK-NEXT: ret i128 2
; CHECK: [[CASE3]]:
; CHECK-NEXT: ret i128 3
;
switch i128 %x, label %default [
i128 0, label %case1
i128 1, label %case2
i128 2, label %case3
i128 3, label %case3
]
default:
ret i128 0
case1:
ret i128 1
case2:
ret i128 2
case3:
ret i128 3
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## switch_case test checking that update_test_checks.py works correctly
# RUN: cp -f %S/Inputs/switch_case.ll %t.ll && %update_test_checks %t.ll --version 7
# RUN: diff -u %t.ll %S/Inputs/switch_case.ll.expected
2 changes: 2 additions & 0 deletions llvm/utils/UpdateTestChecks/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
'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.
"""
DEFAULT_VERSION = 6

Expand Down Expand Up @@ -606,6 +607,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+ \d+, label %\w+")

SCRUB_LEADING_WHITESPACE_RE = re.compile(r"^(\s+)")
SCRUB_WHITESPACE_RE = re.compile(r"(?!^(| \w))[ \t]+", flags=re.M)
Expand Down
12 changes: 10 additions & 2 deletions llvm/utils/update_test_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,17 @@ 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 (
ti.args.version > 6
and 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)
Expand Down