Skip to content

update_test_checks: add new --filter-out-after option #129739

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2025
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
10 changes: 10 additions & 0 deletions clang/test/utils/update_cc_test_checks/Inputs/filter_out_after.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: %clang_cc1 -triple=aarch64-unknown-linux-gnu -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK %s

extern void bar(void);

void foo(int *p, int *q, double *t) {
*p = 5;
*q = 7;
bar();
*t = 1.3l;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --filter-out-after "call.*bar" --version 5
// RUN: %clang_cc1 -triple=aarch64-unknown-linux-gnu -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK %s

extern void bar(void);

// CHECK-LABEL: define dso_local void @foo(
// CHECK-SAME: ptr noundef [[P:%.*]], ptr noundef [[Q:%.*]], ptr noundef [[T:%.*]]) #[[ATTR0:[0-9]+]] {
// CHECK-NEXT: [[ENTRY:.*:]]
// CHECK-NEXT: [[P_ADDR:%.*]] = alloca ptr, align 8
// CHECK-NEXT: [[Q_ADDR:%.*]] = alloca ptr, align 8
// CHECK-NEXT: [[T_ADDR:%.*]] = alloca ptr, align 8
// CHECK-NEXT: store ptr [[P]], ptr [[P_ADDR]], align 8
// CHECK-NEXT: store ptr [[Q]], ptr [[Q_ADDR]], align 8
// CHECK-NEXT: store ptr [[T]], ptr [[T_ADDR]], align 8
// CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr [[P_ADDR]], align 8
// CHECK-NEXT: store i32 5, ptr [[TMP0]], align 4
// CHECK-NEXT: [[TMP1:%.*]] = load ptr, ptr [[Q_ADDR]], align 8
// CHECK-NEXT: store i32 7, ptr [[TMP1]], align 4
// CHECK-NEXT: call void @bar()
//
void foo(int *p, int *q, double *t) {
*p = 5;
*q = 7;
bar();
*t = 1.3l;
}
11 changes: 11 additions & 0 deletions clang/test/utils/update_cc_test_checks/filter_out_after.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Check that --filter_out_after works properly.
# RUN: cp -f %S/Inputs/filter_out_after.c %t.c && %update_cc_test_checks --version=5 --filter-out-after="call.*bar" %t.c
# RUN: diff -u %t.c %S/Inputs/filter_out_after.c.expected

## Check that running the script again does not change the result:
# RUN: %update_cc_test_checks --version=5 --filter-out-after="call.*bar" %t.c
# RUN: diff -u %t.c %S/Inputs/filter_out_after.c.expected

## Check that running the script again, without arguments, does not change the result:
# RUN: %update_cc_test_checks --version=5 %t.c
# RUN: diff -u %t.c %S/Inputs/filter_out_after.c.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
; RUN: opt < %s -S | FileCheck %s

define i32 @func({i32, i32} %x, i32 %y, i1 %cond) {
entry:
br i1 %cond, label %b1, label %b2

b1:
%x.idx0 = extractvalue {i32, i32} %x, 0
%add1 = add i32 %y, 1
%add2 = add i32 %x.idx0, %add1
%mul = mul i32 %add2, 3
br label %b2

b2:
%res = phi i32 [ -1, %entry ], [ %mul, %b1 ]
ret i32 %res
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --filter-out-after "^b2:" --version 5
; RUN: opt < %s -S | FileCheck %s

define i32 @func({i32, i32} %x, i32 %y, i1 %cond) {
; CHECK-LABEL: define i32 @func(
; CHECK-SAME: { i32, i32 } [[X:%.*]], i32 [[Y:%.*]], i1 [[COND:%.*]]) {
; CHECK-NEXT: [[ENTRY:.*:]]
; CHECK-NEXT: br i1 [[COND]], label %[[B1:.*]], label %[[B2:.*]]
; CHECK: [[B1]]:
; CHECK-NEXT: [[X_IDX0:%.*]] = extractvalue { i32, i32 } [[X]], 0
; CHECK-NEXT: [[ADD1:%.*]] = add i32 [[Y]], 1
; CHECK-NEXT: [[ADD2:%.*]] = add i32 [[X_IDX0]], [[ADD1]]
; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[ADD2]], 3
; CHECK-NEXT: br label %[[B2]]
; CHECK: [[B2]]:
;
entry:
br i1 %cond, label %b1, label %b2

b1:
%x.idx0 = extractvalue {i32, i32} %x, 0
%add1 = add i32 %y, 1
%add2 = add i32 %x.idx0, %add1
%mul = mul i32 %add2, 3
br label %b2

b2:
%res = phi i32 [ -1, %entry ], [ %mul, %b1 ]
ret i32 %res
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --filter-out-after "= mul i32" --filter-out-after "^b2:" --version 5
; RUN: opt < %s -S | FileCheck %s

define i32 @func({i32, i32} %x, i32 %y, i1 %cond) {
; CHECK-LABEL: define i32 @func(
; CHECK-SAME: { i32, i32 } [[X:%.*]], i32 [[Y:%.*]], i1 [[COND:%.*]]) {
; CHECK-NEXT: [[ENTRY:.*:]]
; CHECK-NEXT: br i1 [[COND]], label %[[B1:.*]], [[B2:label %.*]]
; CHECK: [[B1]]:
; CHECK-NEXT: [[X_IDX0:%.*]] = extractvalue { i32, i32 } [[X]], 0
; CHECK-NEXT: [[ADD1:%.*]] = add i32 [[Y]], 1
; CHECK-NEXT: [[ADD2:%.*]] = add i32 [[X_IDX0]], [[ADD1]]
; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[ADD2]], 3
;
entry:
br i1 %cond, label %b1, label %b2

b1:
%x.idx0 = extractvalue {i32, i32} %x, 0
%add1 = add i32 %y, 1
%add2 = add i32 %x.idx0, %add1
%mul = mul i32 %add2, 3
br label %b2

b2:
%res = phi i32 [ -1, %entry ], [ %mul, %b1 ]
ret i32 %res
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
; RUN: opt < %s -S | FileCheck %s

define i32 @func1({i32, i32} %x, i32 %y, i1 %cond) {
entry:
br i1 %cond, label %b1, label %b2

b1:
%x.idx0 = extractvalue {i32, i32} %x, 0
%add1 = add i32 %y, 1
%add2 = add i32 %x.idx0, %add1
%mul = mul i32 %add2, 3
br label %b2

b2:
%res = phi i32 [ -1, %entry ], [ %mul, %b1 ]
ret i32 %res
}

define i32 @func2({i32, i32} %x, i32 %y, i1 %cond) {
entry:
br i1 %cond, label %b2, label %b0

b2:
%x.idx0 = extractvalue {i32, i32} %x, 0
%add1 = add i32 %y, 1
%add2 = add i32 %x.idx0, %add1
%mul = mul i32 %add2, 3
br label %b0

b0:
%res = phi i32 [ -1, %entry ], [ %mul, %b2 ]
ret i32 %res
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --filter-out-after "^b2:" --version 5
; RUN: opt < %s -S | FileCheck %s

define i32 @func1({i32, i32} %x, i32 %y, i1 %cond) {
; CHECK-LABEL: define i32 @func1(
; CHECK-SAME: { i32, i32 } [[X:%.*]], i32 [[Y:%.*]], i1 [[COND:%.*]]) {
; CHECK-NEXT: [[ENTRY:.*:]]
; CHECK-NEXT: br i1 [[COND]], label %[[B1:.*]], label %[[B2:.*]]
; CHECK: [[B1]]:
; CHECK-NEXT: [[X_IDX0:%.*]] = extractvalue { i32, i32 } [[X]], 0
; CHECK-NEXT: [[ADD1:%.*]] = add i32 [[Y]], 1
; CHECK-NEXT: [[ADD2:%.*]] = add i32 [[X_IDX0]], [[ADD1]]
; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[ADD2]], 3
; CHECK-NEXT: br label %[[B2]]
; CHECK: [[B2]]:
;
entry:
br i1 %cond, label %b1, label %b2

b1:
%x.idx0 = extractvalue {i32, i32} %x, 0
%add1 = add i32 %y, 1
%add2 = add i32 %x.idx0, %add1
%mul = mul i32 %add2, 3
br label %b2

b2:
%res = phi i32 [ -1, %entry ], [ %mul, %b1 ]
ret i32 %res
}

define i32 @func2({i32, i32} %x, i32 %y, i1 %cond) {
; CHECK-LABEL: define i32 @func2(
; CHECK-SAME: { i32, i32 } [[X:%.*]], i32 [[Y:%.*]], i1 [[COND:%.*]]) {
; CHECK-NEXT: [[ENTRY:.*:]]
; CHECK-NEXT: br i1 [[COND]], label %[[B2:.*]], [[B0:label %.*]]
; CHECK: [[B2]]:
;
entry:
br i1 %cond, label %b2, label %b0

b2:
%x.idx0 = extractvalue {i32, i32} %x, 0
%add1 = add i32 %y, 1
%add2 = add i32 %x.idx0, %add1
%mul = mul i32 %add2, 3
br label %b0

b0:
%res = phi i32 [ -1, %entry ], [ %mul, %b2 ]
ret i32 %res
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
; RUN: opt -S -mtriple aarch64-linux-gnu -passes=instnamer < %s | FileCheck %s

define i32 @f_0(i32) {
%2 = add i32 %0, 2
br label %3

; <label>:3:
ret i32 %2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --filter-out-after "br label %3" --version 5
; RUN: opt -S -mtriple aarch64-linux-gnu -passes=instnamer < %s | FileCheck %s

define i32 @f_0(i32) {
; CHECK-LABEL: define i32 @f_0(
; CHECK-SAME: i32 [[ARG:%.*]]) {
; CHECK-NEXT: [[BB:.*:]]
; CHECK-NEXT: [[I:%.*]] = add i32 [[ARG]], 2
; CHECK-NEXT: br label %[[BB1:.*]]
; CHECK: [[BB1]]:
; CHECK-NEXT: ret i32 [[I]]
;
%2 = add i32 %0, 2
br label %3

; <label>:3:
ret i32 %2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
## Check that --filter-out-after works properly.
# RUN: cp -f %S/Inputs/filter-out-after.ll %t.ll && %update_test_checks --version=5 --filter-out-after="^b2:" %t.ll
# RUN: diff -u %t.ll %S/Inputs/filter-out-after.ll.expected

## Check that running the script again does not change the result:
# RUN: %update_test_checks --version=5 --filter-out-after="^b2:" %t.ll
# RUN: diff -u %t.ll %S/Inputs/filter-out-after.ll.expected

## Check that running the script again, without arguments, does not change the result:
# RUN: %update_test_checks --version=5 %t.ll
# RUN: diff -u %t.ll %S/Inputs/filter-out-after.ll.expected

## Check that multiple --filter-out-after options work properly.
# RUN: cp -f %S/Inputs/filter-out-after.ll %t.ll && %update_test_checks --version=5 --filter-out-after="= mul i32" --filter-out-after="^b2:" %t.ll
# RUN: diff -u %t.ll %S/Inputs/filter-out-after.ll.expected2

## Check that running the script again does not change the result:
# RUN: %update_test_checks --version=5 --filter-out-after="= mul i32" --filter-out-after="^b2:" %t.ll
# RUN: diff -u %t.ll %S/Inputs/filter-out-after.ll.expected2

## Check that running the script again, without arguments, does not change the result:
# RUN: %update_test_checks --version=5 %t.ll
# RUN: diff -u %t.ll %S/Inputs/filter-out-after.ll.expected2

## Check that --filter-out-after works per function only.
# RUN: cp -f %S/Inputs/filter-out-after2.ll %t.ll && %update_test_checks --version=5 --filter-out-after="^b2:" %t.ll
# RUN: diff -u %t.ll %S/Inputs/filter-out-after2.ll.expected

## Check that running the script again does not change the result:
# RUN: %update_test_checks --version=5 --filter-out-after="^b2:" %t.ll
# RUN: diff -u %t.ll %S/Inputs/filter-out-after2.ll.expected

## Check that running the script again, without arguments, does not change the result:
# RUN: %update_test_checks --version=5 %t.ll
# RUN: diff -u %t.ll %S/Inputs/filter-out-after2.ll.expected

## Check that --filter-out-after does not filter input IR.
# RUN: cp -f %S/Inputs/filter-out-after3.ll %t.ll && %update_test_checks --version=5 --filter-out-after="br label %3" %t.ll
# RUN: diff -u %t.ll %S/Inputs/filter-out-after3.ll.expected
Loading