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,29 @@
; RUN: opt < %s -S | FileCheck %s

; Test whether UTC checks empty lines instead of skipping them.
define i32 @test(i32 %x) {
entry:
br label %block1

block1:
%cmp = icmp eq i32 %x, 0
br i1 %cmp, label %block2, label %exit1

block2:
br i1 %cmp, label %block3, label %exit2

block3:
br i1 %cmp, label %exit3, label %exit4

exit1:
ret i32 0

exit2:
ret i32 %x

exit3:
ret i32 %x

exit4:
ret i32 %x
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 7
; RUN: opt < %s -S | FileCheck %s

; Test whether UTC checks empty lines instead of skipping them.
define i32 @test(i32 %x) {
; CHECK-LABEL: define i32 @test(
; CHECK-SAME: i32 [[X:%.*]]) {
; CHECK-NEXT: [[ENTRY:.*:]]
; CHECK-NEXT: br label %[[BLOCK1:.*]]
; CHECK-EMPTY:
; CHECK-NEXT: [[BLOCK1]]:
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[X]], 0
; CHECK-NEXT: br i1 [[CMP]], label %[[BLOCK2:.*]], label %[[EXIT1:.*]]
; CHECK-EMPTY:
; CHECK-NEXT: [[BLOCK2]]:
; CHECK-NEXT: br i1 [[CMP]], label %[[BLOCK3:.*]], label %[[EXIT2:.*]]
; CHECK-EMPTY:
; CHECK-NEXT: [[BLOCK3]]:
; CHECK-NEXT: br i1 [[CMP]], label %[[EXIT3:.*]], label %[[EXIT4:.*]]
; CHECK-EMPTY:
; CHECK-NEXT: [[EXIT1]]:
; CHECK-NEXT: ret i32 0
; CHECK-EMPTY:
; CHECK-NEXT: [[EXIT2]]:
; CHECK-NEXT: ret i32 [[X]]
; CHECK-EMPTY:
; CHECK-NEXT: [[EXIT3]]:
; CHECK-NEXT: ret i32 [[X]]
; CHECK-EMPTY:
; CHECK-NEXT: [[EXIT4]]:
; CHECK-NEXT: ret i32 [[X]]
;
entry:
br label %block1

block1:
%cmp = icmp eq i32 %x, 0
br i1 %cmp, label %block2, label %exit1

block2:
br i1 %cmp, label %block3, label %exit2

block3:
br i1 %cmp, label %exit3, label %exit4

exit1:
ret i32 0

exit2:
ret i32 %x

exit3:
ret i32 %x

exit4:
ret i32 %x
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ define i8 @testi8(i8 %x) {
; CHECK-NEXT: i8 2, label %[[CASE3:.*]]
; CHECK-NEXT: i8 3, label %[[CASE3]]
; CHECK-NEXT: ]
; CHECK: [[DEFAULT]]:
; CHECK-EMPTY:
; CHECK-NEXT: [[DEFAULT]]:
; CHECK-NEXT: ret i8 0
; CHECK: [[CASE1]]:
; CHECK-EMPTY:
; CHECK-NEXT: [[CASE1]]:
; CHECK-NEXT: ret i8 1
; CHECK: [[CASE2]]:
; CHECK-EMPTY:
; CHECK-NEXT: [[CASE2]]:
; CHECK-NEXT: ret i8 2
; CHECK: [[CASE3]]:
; CHECK-EMPTY:
; CHECK-NEXT: [[CASE3]]:
; CHECK-NEXT: ret i8 3
;
switch i8 %x, label %default [
Expand Down Expand Up @@ -46,13 +50,17 @@ define i32 @testi32(i32 %x) {
; CHECK-NEXT: i32 2, label %[[CASE3:.*]]
; CHECK-NEXT: i32 3, label %[[CASE3]]
; CHECK-NEXT: ]
; CHECK: [[DEFAULT]]:
; CHECK-EMPTY:
; CHECK-NEXT: [[DEFAULT]]:
; CHECK-NEXT: ret i32 0
; CHECK: [[CASE1]]:
; CHECK-EMPTY:
; CHECK-NEXT: [[CASE1]]:
; CHECK-NEXT: ret i32 1
; CHECK: [[CASE2]]:
; CHECK-EMPTY:
; CHECK-NEXT: [[CASE2]]:
; CHECK-NEXT: ret i32 2
; CHECK: [[CASE3]]:
; CHECK-EMPTY:
; CHECK-NEXT: [[CASE3]]:
; CHECK-NEXT: ret i32 3
;
switch i32 %x, label %default [
Expand Down Expand Up @@ -80,13 +88,17 @@ define i128 @testi128(i128 %x) {
; CHECK-NEXT: i128 2, label %[[CASE3:.*]]
; CHECK-NEXT: i128 3, label %[[CASE3]]
; CHECK-NEXT: ]
; CHECK: [[DEFAULT]]:
; CHECK-EMPTY:
; CHECK-NEXT: [[DEFAULT]]:
; CHECK-NEXT: ret i128 0
; CHECK: [[CASE1]]:
; CHECK-EMPTY:
; CHECK-NEXT: [[CASE1]]:
; CHECK-NEXT: ret i128 1
; CHECK: [[CASE2]]:
; CHECK-EMPTY:
; CHECK-NEXT: [[CASE2]]:
; CHECK-NEXT: ret i128 2
; CHECK: [[CASE3]]:
; CHECK-EMPTY:
; CHECK-NEXT: [[CASE3]]:
; CHECK-NEXT: ret i128 3
;
switch i128 %x, label %default [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## test whether the UTC generates CHECK-EMPTY for blank lines
# RUN: cp -f %S/Inputs/check_empty.ll %t.ll && %update_test_checks %t.ll --version 7
# RUN: diff -u %t.ll %S/Inputs/check_empty.ll.expected
23 changes: 20 additions & 3 deletions llvm/utils/UpdateTestChecks/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +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.
7: Indent switch-cases correctly; CHECK-EMPTY instead of skipping blank lines.
"""
DEFAULT_VERSION = 6

Expand Down Expand Up @@ -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,
Expand All @@ -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.
Expand Down