Skip to content

Commit ce583b1

Browse files
committed
[utils] Avoid hardcoding metadata ids in update_cc_test_checks
Specifically for: !tbaa, !tbaa.struct, !annotation, !srcloc, !nosanitize. The goal is to avoid test brittleness caused by hardcoded values. Differential Revision: https://reviews.llvm.org/D123273
1 parent f0ea9c9 commit ce583b1

16 files changed

+222
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %clang_cc1 -ftrivial-auto-var-init=zero -triple=x86_64-unknown-linux-gnu -O1 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s
2+
3+
void foo_ptr_to_scalar() {
4+
unsigned long long* a[100];
5+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
2+
// RUN: %clang_cc1 -ftrivial-auto-var-init=zero -triple=x86_64-unknown-linux-gnu -O1 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s
3+
4+
// CHECK-LABEL: @foo_ptr_to_scalar(
5+
// CHECK-NEXT: entry:
6+
// CHECK-NEXT: [[A:%.*]] = alloca [100 x i64*], align 16
7+
// CHECK-NEXT: [[TMP0:%.*]] = bitcast [100 x i64*]* [[A]] to i8*
8+
// CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 800, i8* [[TMP0]]) #[[ATTR3:[0-9]+]]
9+
// CHECK-NEXT: [[TMP1:%.*]] = bitcast [100 x i64*]* [[A]] to i8*
10+
// CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* align 16 [[TMP1]], i8 0, i64 800, i1 false), !annotation [[ANNT2:![0-9]+]]
11+
// CHECK-NEXT: [[TMP2:%.*]] = bitcast [100 x i64*]* [[A]] to i8*
12+
// CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 800, i8* [[TMP2]]) #[[ATTR3]]
13+
// CHECK-NEXT: ret void
14+
//
15+
void foo_ptr_to_scalar() {
16+
unsigned long long* a[100];
17+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %clang_cc1 -fsanitize=shift-exponent,shift-base -triple=x86_64-unknown-linux-gnu -O1 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s
2+
3+
void foo(int* c, int* shamt) {
4+
*c = 1 << (*c << *shamt);
5+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
2+
// RUN: %clang_cc1 -fsanitize=shift-exponent,shift-base -triple=x86_64-unknown-linux-gnu -O1 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s
3+
4+
// CHECK-LABEL: @foo(
5+
// CHECK-NEXT: entry:
6+
// CHECK-NEXT: [[C_ADDR:%.*]] = alloca i32*, align 8
7+
// CHECK-NEXT: [[SHAMT_ADDR:%.*]] = alloca i32*, align 8
8+
// CHECK-NEXT: store i32* [[C:%.*]], i32** [[C_ADDR]], align 8, !tbaa [[TBAA2:![0-9]+]]
9+
// CHECK-NEXT: store i32* [[SHAMT:%.*]], i32** [[SHAMT_ADDR]], align 8, !tbaa [[TBAA2]]
10+
// CHECK-NEXT: [[TMP0:%.*]] = load i32*, i32** [[C_ADDR]], align 8, !tbaa [[TBAA2]]
11+
// CHECK-NEXT: [[TMP1:%.*]] = load i32, i32* [[TMP0]], align 4, !tbaa [[TBAA6:![0-9]+]]
12+
// CHECK-NEXT: [[TMP2:%.*]] = load i32*, i32** [[SHAMT_ADDR]], align 8, !tbaa [[TBAA2]]
13+
// CHECK-NEXT: [[TMP3:%.*]] = load i32, i32* [[TMP2]], align 4, !tbaa [[TBAA6]]
14+
// CHECK-NEXT: [[TMP4:%.*]] = icmp ule i32 [[TMP3]], 31, !nosanitize [[NOSAN8:![0-9]+]]
15+
// CHECK-NEXT: br i1 [[TMP4]], label [[CHECK:%.*]], label [[CONT:%.*]], !nosanitize [[NOSAN8]]
16+
// CHECK: check:
17+
// CHECK-NEXT: [[SHL_ZEROS:%.*]] = sub nuw nsw i32 31, [[TMP3]], !nosanitize [[NOSAN8]]
18+
// CHECK-NEXT: [[SHL_CHECK:%.*]] = lshr i32 [[TMP1]], [[SHL_ZEROS]], !nosanitize [[NOSAN8]]
19+
// CHECK-NEXT: [[TMP5:%.*]] = icmp eq i32 [[SHL_CHECK]], 0, !nosanitize [[NOSAN8]]
20+
// CHECK-NEXT: br label [[CONT]], !nosanitize [[NOSAN8]]
21+
// CHECK: cont:
22+
// CHECK-NEXT: [[TMP6:%.*]] = phi i1 [ true, [[ENTRY:%.*]] ], [ [[TMP5]], [[CHECK]] ], !nosanitize [[NOSAN8]]
23+
// CHECK-NEXT: [[TMP7:%.*]] = and i1 [[TMP4]], [[TMP6]], !nosanitize [[NOSAN8]]
24+
// CHECK-NEXT: br i1 [[TMP7]], label [[CONT1:%.*]], label [[HANDLER_SHIFT_OUT_OF_BOUNDS:%.*]], !prof [[PROF9:![0-9]+]], !nosanitize [[NOSAN8]]
25+
// CHECK: handler.shift_out_of_bounds:
26+
// CHECK-NEXT: [[TMP8:%.*]] = zext i32 [[TMP1]] to i64, !nosanitize [[NOSAN8]]
27+
// CHECK-NEXT: [[TMP9:%.*]] = zext i32 [[TMP3]] to i64, !nosanitize [[NOSAN8]]
28+
// CHECK-NEXT: call void @__ubsan_handle_shift_out_of_bounds_abort(i8* bitcast ({ { [124 x i8]*, i32, i32 }, { i16, i16, [6 x i8] }*, { i16, i16, [6 x i8] }* }* @[[GLOB1:[0-9]+]] to i8*), i64 [[TMP8]], i64 [[TMP9]]) #[[ATTR2:[0-9]+]], !nosanitize [[NOSAN8]]
29+
// CHECK-NEXT: unreachable, !nosanitize [[NOSAN8]]
30+
// CHECK: cont1:
31+
// CHECK-NEXT: [[SHL:%.*]] = shl i32 [[TMP1]], [[TMP3]]
32+
// CHECK-NEXT: [[TMP10:%.*]] = icmp ule i32 [[SHL]], 31, !nosanitize [[NOSAN8]]
33+
// CHECK-NEXT: br i1 [[TMP10]], label [[CHECK2:%.*]], label [[CONT5:%.*]], !nosanitize [[NOSAN8]]
34+
// CHECK: check2:
35+
// CHECK-NEXT: [[SHL_ZEROS3:%.*]] = sub nuw nsw i32 31, [[SHL]], !nosanitize [[NOSAN8]]
36+
// CHECK-NEXT: [[SHL_CHECK4:%.*]] = lshr i32 1, [[SHL_ZEROS3]], !nosanitize [[NOSAN8]]
37+
// CHECK-NEXT: [[TMP11:%.*]] = icmp eq i32 [[SHL_CHECK4]], 0, !nosanitize [[NOSAN8]]
38+
// CHECK-NEXT: br label [[CONT5]], !nosanitize [[NOSAN8]]
39+
// CHECK: cont5:
40+
// CHECK-NEXT: [[TMP12:%.*]] = phi i1 [ true, [[CONT1]] ], [ [[TMP11]], [[CHECK2]] ], !nosanitize [[NOSAN8]]
41+
// CHECK-NEXT: [[TMP13:%.*]] = and i1 [[TMP10]], [[TMP12]], !nosanitize [[NOSAN8]]
42+
// CHECK-NEXT: br i1 [[TMP13]], label [[CONT7:%.*]], label [[HANDLER_SHIFT_OUT_OF_BOUNDS6:%.*]], !prof [[PROF9]], !nosanitize [[NOSAN8]]
43+
// CHECK: handler.shift_out_of_bounds6:
44+
// CHECK-NEXT: [[TMP14:%.*]] = zext i32 [[SHL]] to i64, !nosanitize [[NOSAN8]]
45+
// CHECK-NEXT: call void @__ubsan_handle_shift_out_of_bounds_abort(i8* bitcast ({ { [124 x i8]*, i32, i32 }, { i16, i16, [6 x i8] }*, { i16, i16, [6 x i8] }* }* @[[GLOB2:[0-9]+]] to i8*), i64 1, i64 [[TMP14]]) #[[ATTR2]], !nosanitize [[NOSAN8]]
46+
// CHECK-NEXT: unreachable, !nosanitize [[NOSAN8]]
47+
// CHECK: cont7:
48+
// CHECK-NEXT: [[SHL8:%.*]] = shl i32 1, [[SHL]]
49+
// CHECK-NEXT: [[TMP15:%.*]] = load i32*, i32** [[C_ADDR]], align 8, !tbaa [[TBAA2]]
50+
// CHECK-NEXT: store i32 [[SHL8]], i32* [[TMP15]], align 4, !tbaa [[TBAA6]]
51+
// CHECK-NEXT: ret void
52+
//
53+
void foo(int* c, int* shamt) {
54+
*c = 1 << (*c << *shamt);
55+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -O1 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s
2+
__attribute__((error("oh no"))) void foo(void);
3+
4+
void bar(void) {
5+
foo();
6+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
2+
// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -O1 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s
3+
__attribute__((error("oh no"))) void foo(void);
4+
5+
// CHECK-LABEL: @bar(
6+
// CHECK-NEXT: entry:
7+
// CHECK-NEXT: call void @foo(), !srcloc [[SRCLOC2:![0-9]+]]
8+
// CHECK-NEXT: ret void
9+
//
10+
void bar(void) {
11+
foo();
12+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -O1 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s
2+
3+
void foo(unsigned **ptr) {
4+
*ptr = 0;
5+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
2+
// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -O1 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s
3+
4+
// CHECK-LABEL: @foo(
5+
// CHECK-NEXT: entry:
6+
// CHECK-NEXT: [[PTR_ADDR:%.*]] = alloca i32**, align 8
7+
// CHECK-NEXT: store i32** [[PTR:%.*]], i32*** [[PTR_ADDR]], align 8, !tbaa [[TBAA2:![0-9]+]]
8+
// CHECK-NEXT: [[TMP0:%.*]] = load i32**, i32*** [[PTR_ADDR]], align 8, !tbaa [[TBAA2]]
9+
// CHECK-NEXT: store i32* null, i32** [[TMP0]], align 8, !tbaa [[TBAA2]]
10+
// CHECK-NEXT: ret void
11+
//
12+
void foo(unsigned **ptr) {
13+
*ptr = 0;
14+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %clang_cc1 -flegacy-pass-manager -triple arm64-apple-iphoneos -Oz -mllvm -enable-constraint-elimination=true -fpass-by-value-is-noalias -emit-llvm -o - %s | FileCheck %s
2+
3+
typedef struct {
4+
void *a;
5+
void *b;
6+
void *c;
7+
void *d;
8+
void *e;
9+
} Foo;
10+
11+
static void bar(Foo f) {
12+
if (f.b)
13+
__builtin_trap();
14+
}
15+
16+
static int baz(Foo f) {
17+
bar(f);
18+
return *(int *)f.a;
19+
}
20+
21+
int barbar(Foo arg) {
22+
int a, b;
23+
a = baz(arg);
24+
return a - b;
25+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
2+
// RUN: %clang_cc1 -flegacy-pass-manager -triple arm64-apple-iphoneos -Oz -mllvm -enable-constraint-elimination=true -fpass-by-value-is-noalias -emit-llvm -o - %s | FileCheck %s
3+
4+
typedef struct {
5+
void *a;
6+
void *b;
7+
void *c;
8+
void *d;
9+
void *e;
10+
} Foo;
11+
12+
static void bar(Foo f) {
13+
if (f.b)
14+
__builtin_trap();
15+
}
16+
17+
static int baz(Foo f) {
18+
bar(f);
19+
return *(int *)f.a;
20+
}
21+
22+
// CHECK-LABEL: @barbar(
23+
// CHECK-NEXT: entry:
24+
// CHECK-NEXT: [[BYVAL_TEMP_SROA_3_0__SROA_IDX4:%.*]] = getelementptr inbounds [[STRUCT_FOO:%.*]], %struct.Foo* [[ARG:%.*]], i64 0, i32 1
25+
// CHECK-NEXT: [[BYVAL_TEMP_SROA_3_0_COPYLOAD:%.*]] = load i8*, i8** [[BYVAL_TEMP_SROA_3_0__SROA_IDX4]], align 8, !tbaa.struct [[TBAAST6:![0-9]+]]
26+
// CHECK-NEXT: [[TOBOOL_NOT_I_I:%.*]] = icmp eq i8* [[BYVAL_TEMP_SROA_3_0_COPYLOAD]], null
27+
// CHECK-NEXT: br i1 [[TOBOOL_NOT_I_I]], label [[BAZ_EXIT:%.*]], label [[IF_THEN_I_I:%.*]]
28+
// CHECK: if.then.i.i:
29+
// CHECK-NEXT: tail call void @llvm.trap() #[[ATTR2:[0-9]+]], !noalias !11
30+
// CHECK-NEXT: unreachable
31+
// CHECK: baz.exit:
32+
// CHECK-NEXT: ret i32 undef
33+
//
34+
int barbar(Foo arg) {
35+
int a, b;
36+
a = baz(arg);
37+
return a - b;
38+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Test that CHECK lines are generated before the definion and not the declaration
2+
3+
# RUN: cp %S/Inputs/annotation-id.c %t.c && %update_cc_test_checks %t.c
4+
# RUN: diff -u %S/Inputs/annotation-id.expected %t.c
5+
## Check that re-running update_cc_test_checks doesn't change the output
6+
# RUN: %update_cc_test_checks %t.c
7+
# RUN: diff -u %S/Inputs/annotation-id.expected %t.c
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Test that CHECK lines are generated before the definion and not the declaration
2+
3+
# RUN: cp %S/Inputs/nosanitize-id.c %t.c && %update_cc_test_checks %t.c
4+
# RUN: diff -u %S/Inputs/nosanitize-id.expected %t.c
5+
## Check that re-running update_cc_test_checks doesn't change the output
6+
# RUN: %update_cc_test_checks %t.c
7+
# RUN: diff -u %S/Inputs/nosanitize-id.expected %t.c
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Test that CHECK lines are generated before the definion and not the declaration
2+
3+
# RUN: cp %S/Inputs/srcloc-id.c %t.c && %update_cc_test_checks %t.c
4+
# RUN: diff -u %S/Inputs/srcloc-id.expected %t.c
5+
## Check that re-running update_cc_test_checks doesn't change the output
6+
# RUN: %update_cc_test_checks %t.c
7+
# RUN: diff -u %S/Inputs/srcloc-id.expected %t.c
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Test that CHECK lines are generated before the definion and not the declaration
2+
3+
# RUN: cp %S/Inputs/tbaa-id.c %t.c && %update_cc_test_checks %t.c
4+
# RUN: diff -u %S/Inputs/tbaa-id.expected %t.c
5+
## Check that re-running update_cc_test_checks doesn't change the output
6+
# RUN: %update_cc_test_checks %t.c
7+
# RUN: diff -u %S/Inputs/tbaa-id.expected %t.c
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Test that CHECK lines are generated before the definion and not the declaration
2+
3+
# RUN: cp %S/Inputs/tbaa-struct-id.c %t.c && %update_cc_test_checks %t.c
4+
# RUN: diff -u %S/Inputs/tbaa-struct-id.expected %t.c
5+
## Check that re-running update_cc_test_checks doesn't change the output
6+
# RUN: %update_cc_test_checks %t.c
7+
# RUN: diff -u %S/Inputs/tbaa-struct-id.expected %t.c

llvm/utils/UpdateTestChecks/common.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,11 +616,15 @@ def __init__(self, check_prefix, check_key, ir_prefix, global_ir_prefix, global_
616616
NamelessValue(r'GLOB' , '@' , None , r'@' , r'[a-zA-Z0-9_$"\\.-]+' , None , r'.+' , True) ,
617617
NamelessValue(r'DBG' , '!' , r'!dbg ' , None , None , r'![0-9]+' , None , False) ,
618618
NamelessValue(r'PROF' , '!' , r'!prof ' , None , None , r'![0-9]+' , None , False) ,
619-
NamelessValue(r'TBAA' , '!' , r'!tbaa ' , None , None , r'![0-9]+' , None , False) ,
620619
NamelessValue(r'RNG' , '!' , r'!range ' , None , None , r'![0-9]+' , None , False) ,
621620
NamelessValue(r'LOOP' , '!' , r'!llvm.loop ' , None , None , r'![0-9]+' , None , False) ,
622621
NamelessValue(r'META' , '!' , r'metadata ' , None , None , r'![0-9]+' , None , False) ,
623622
NamelessValue(r'META' , '!' , None , r'' , r'![0-9]+' , None , r'(?:distinct |)!.*' , False) ,
623+
NamelessValue(r'TBAA' , '!' , r'!tbaa ' , None , None , r'![0-9]+' , None , False) ,
624+
NamelessValue(r'TBAAST' , '!' , r'!tbaa.struct ', None , None , r'![0-9]+' , None , False) ,
625+
NamelessValue(r'ANNT' , '!' , r'!annotation ' , None , None , r'![0-9]+' , None , False) ,
626+
NamelessValue(r'SRCLOC' , '!' , r'!srcloc ' , None , None , r'![0-9]+' , None , False) ,
627+
NamelessValue(r'NOSAN' , '!' , r'!nosanitize ' , None , None , r'![0-9]+' , None , False) ,
624628
]
625629

626630
def createOrRegexp(old, new):

0 commit comments

Comments
 (0)