Skip to content

Commit 97ce7fd

Browse files
committed
[UpdateTestChecks] Match unnamed values like "@[0-9]+" and "![0-9]+"
With this patch we will match most *uses* of "temporary" named things in the IR via regular expressions, not their name at creation time. The new "values" we match are: - "unnamed" globals: `@[0-9]+` - debug metadata: `!dbg ![0-9]+` - loop metadata: `!loop ![0-9]+` - tbaa metadata: `!tbaa ![0-9]+` - range metadata: `!range ![0-9]+` - generic metadata: `metadata ![0-9]+` - attributes groups: `#[0-9]` We still don't match the declarations but that can be done later. This patch can introduce churn when existing check lines contain the old hardcoded versions of the above "values". We can add a flag to opt-out, or opt-in, if necessary. Reviewed By: arichardson, MaskRay Differential Revision: https://reviews.llvm.org/D85099
1 parent 31e5f71 commit 97ce7fd

File tree

13 files changed

+807
-48
lines changed

13 files changed

+807
-48
lines changed

clang/test/utils/update_cc_test_checks/Inputs/basic-cplusplus.cpp.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Foo::Foo(int x) : x(x) {}
4444
// CHECK-NEXT: [[THIS_ADDR:%.*]] = alloca %class.Foo*, align 8
4545
// CHECK-NEXT: store %class.Foo* [[THIS:%.*]], %class.Foo** [[THIS_ADDR]], align 8
4646
// CHECK-NEXT: [[THIS1:%.*]] = load %class.Foo*, %class.Foo** [[THIS_ADDR]], align 8
47-
// CHECK-NEXT: call void @_ZN3FooD2Ev(%class.Foo* [[THIS1]]) #2
47+
// CHECK-NEXT: call void @_ZN3FooD2Ev(%class.Foo* [[THIS1]]) [[ATTR2:#.*]]
4848
// CHECK-NEXT: ret void
4949
//
5050
Foo::~Foo() {}
@@ -70,7 +70,7 @@ int Foo::function_defined_out_of_line(int arg) const { return x - arg; }
7070
// CHECK-NEXT: call void @_ZN3FooC1Ei(%class.Foo* [[F]], i32 1)
7171
// CHECK-NEXT: [[CALL:%.*]] = call i32 @_ZNK3Foo23function_defined_inlineEi(%class.Foo* [[F]], i32 2)
7272
// CHECK-NEXT: [[CALL1:%.*]] = call i32 @_ZNK3Foo28function_defined_out_of_lineEi(%class.Foo* [[F]], i32 3)
73-
// CHECK-NEXT: call void @_ZN3FooD1Ev(%class.Foo* [[F]]) #2
73+
// CHECK-NEXT: call void @_ZN3FooD1Ev(%class.Foo* [[F]]) [[ATTR2]]
7474
// CHECK-NEXT: ret i32 0
7575
//
7676
int main() {

clang/test/utils/update_cc_test_checks/Inputs/mangled_names.c.funcsig.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s | FileCheck %s
44

55
// CHECK-LABEL: define {{[^@]+}}@test
6-
// CHECK-SAME: (i64 [[A:%.*]], i32 [[B:%.*]]) #0
6+
// CHECK-SAME: (i64 [[A:%.*]], i32 [[B:%.*]]) [[ATTR0:#.*]]
77
// CHECK-NEXT: entry:
88
// CHECK-NEXT: [[A_ADDR:%.*]] = alloca i64, align 8
99
// CHECK-NEXT: [[B_ADDR:%.*]] = alloca i32, align 4
@@ -21,7 +21,7 @@ long test(long a, int b) {
2121

2222
// A function with a mangled name
2323
// CHECK-LABEL: define {{[^@]+}}@_Z4testlii
24-
// CHECK-SAME: (i64 [[A:%.*]], i32 [[B:%.*]], i32 [[C:%.*]]) #0
24+
// CHECK-SAME: (i64 [[A:%.*]], i32 [[B:%.*]], i32 [[C:%.*]]) [[ATTR0]]
2525
// CHECK-NEXT: entry:
2626
// CHECK-NEXT: [[A_ADDR:%.*]] = alloca i64, align 8
2727
// CHECK-NEXT: [[B_ADDR:%.*]] = alloca i32, align 4

llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/check_attrs.ll.funcattrs.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
define i32* @foo(%struct.ST* %s) nounwind uwtable readnone optsize ssp {
1111
; IS__TUNIT____: Function Attrs: nofree nosync nounwind optsize readnone ssp uwtable willreturn
1212
; IS__TUNIT____-LABEL: define {{[^@]+}}@foo
13-
; IS__TUNIT____-SAME: (%struct.ST* nofree readnone [[S:%.*]]) #0
13+
; IS__TUNIT____-SAME: (%struct.ST* nofree readnone [[S:%.*]]) [[ATTR0:#.*]]
1414
; IS__TUNIT____-NEXT: entry:
1515
; IS__TUNIT____-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [[STRUCT_ST:%.*]], %struct.ST* [[S]], i64 1, i32 2, i32 1, i64 5, i64 13
1616
; IS__TUNIT____-NEXT: ret i32* [[ARRAYIDX]]
1717
;
1818
; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind optsize readnone ssp uwtable willreturn
1919
; IS__CGSCC____-LABEL: define {{[^@]+}}@foo
20-
; IS__CGSCC____-SAME: (%struct.ST* nofree readnone [[S:%.*]]) #0
20+
; IS__CGSCC____-SAME: (%struct.ST* nofree readnone [[S:%.*]]) [[ATTR0:#.*]]
2121
; IS__CGSCC____-NEXT: entry:
2222
; IS__CGSCC____-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [[STRUCT_ST:%.*]], %struct.ST* [[S]], i64 1, i32 2, i32 1, i64 5, i64 13
2323
; IS__CGSCC____-NEXT: ret i32* [[ARRAYIDX]]

llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/check_attrs.ll.plain.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
define i32* @foo(%struct.ST* %s) nounwind uwtable readnone optsize ssp {
1111
; CHECK-LABEL: define {{[^@]+}}@foo
12-
; CHECK-SAME: (%struct.ST* nofree readnone [[S:%.*]]) #0
12+
; CHECK-SAME: (%struct.ST* nofree readnone [[S:%.*]]) [[ATTR0:#.*]]
1313
; CHECK-NEXT: entry:
1414
; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [[STRUCT_ST:%.*]], %struct.ST* [[S]], i64 1, i32 2, i32 1, i64 5, i64 13
1515
; CHECK-NEXT: ret i32* [[ARRAYIDX]]

llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/scrub_attrs.ll.plain.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ declare void @foo()
55

66
define internal void @bar() {
77
; CHECK-LABEL: @bar(
8-
; CHECK-NEXT: call void @foo() #0
8+
; CHECK-NEXT: call void @foo() [[ATTR0:#.*]]
99
; CHECK-NEXT: ret void
1010
;
1111
call void @foo() readnone
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
; Just run it through opt, no passes needed.
2+
; RUN: opt < %s -S | FileCheck %s
3+
4+
; ModuleID = 'various_ir_values.c'
5+
source_filename = "various_ir_values.c"
6+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
7+
target triple = "x86_64-unknown-linux-gnu"
8+
9+
; Function Attrs: nounwind uwtable
10+
define dso_local void @foo(i32* %A) #0 !dbg !7 {
11+
entry:
12+
%A.addr = alloca i32*, align 8
13+
%i = alloca i32, align 4
14+
store i32* %A, i32** %A.addr, align 8, !tbaa !16
15+
call void @llvm.dbg.declare(metadata i32** %A.addr, metadata !13, metadata !DIExpression()), !dbg !20
16+
%0 = bitcast i32* %i to i8*, !dbg !21
17+
call void @llvm.lifetime.start.p0i8(i64 4, i8* %0) #3, !dbg !21
18+
call void @llvm.dbg.declare(metadata i32* %i, metadata !14, metadata !DIExpression()), !dbg !22
19+
store i32 0, i32* %i, align 4, !dbg !22, !tbaa !23
20+
br label %for.cond, !dbg !21
21+
22+
for.cond: ; preds = %for.inc, %entry
23+
%1 = load i32, i32* %i, align 4, !dbg !25, !tbaa !23
24+
%2 = load i32*, i32** %A.addr, align 8, !dbg !27, !tbaa !16
25+
%3 = load i32, i32* %2, align 4, !dbg !28, !tbaa !23
26+
%cmp = icmp slt i32 %1, %3, !dbg !29
27+
br i1 %cmp, label %for.body, label %for.cond.cleanup, !dbg !30
28+
29+
for.cond.cleanup: ; preds = %for.cond
30+
%4 = bitcast i32* %i to i8*, !dbg !31
31+
call void @llvm.lifetime.end.p0i8(i64 4, i8* %4) #3, !dbg !31
32+
br label %for.end
33+
34+
for.body: ; preds = %for.cond
35+
%5 = load i32*, i32** %A.addr, align 8, !dbg !32, !tbaa !16
36+
%6 = load i32, i32* %i, align 4, !dbg !33, !tbaa !23
37+
%idxprom = sext i32 %6 to i64, !dbg !32
38+
%arrayidx = getelementptr inbounds i32, i32* %5, i64 %idxprom, !dbg !32
39+
store i32 0, i32* %arrayidx, align 4, !dbg !34, !tbaa !23
40+
br label %for.inc, !dbg !32
41+
42+
for.inc: ; preds = %for.body
43+
%7 = load i32, i32* %i, align 4, !dbg !35, !tbaa !23
44+
%inc = add nsw i32 %7, 1, !dbg !35
45+
store i32 %inc, i32* %i, align 4, !dbg !35, !tbaa !23
46+
br label %for.cond, !dbg !31, !llvm.loop !36
47+
48+
for.end: ; preds = %for.cond.cleanup
49+
ret void, !dbg !38
50+
}
51+
52+
; Function Attrs: nounwind readnone speculatable willreturn
53+
declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
54+
55+
; Function Attrs: argmemonly nounwind willreturn
56+
declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #2
57+
58+
; Function Attrs: argmemonly nounwind willreturn
59+
declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #2
60+
61+
; Function Attrs: nounwind uwtable
62+
define dso_local void @bar(i32* %A) #0 !dbg !39 {
63+
entry:
64+
%A.addr = alloca i32*, align 8
65+
%i = alloca i32, align 4
66+
store i32* %A, i32** %A.addr, align 8, !tbaa !16
67+
call void @llvm.dbg.declare(metadata i32** %A.addr, metadata !41, metadata !DIExpression()), !dbg !44
68+
%0 = bitcast i32* %i to i8*, !dbg !45
69+
call void @llvm.lifetime.start.p0i8(i64 4, i8* %0) #3, !dbg !45
70+
call void @llvm.dbg.declare(metadata i32* %i, metadata !42, metadata !DIExpression()), !dbg !46
71+
store i32 0, i32* %i, align 4, !dbg !46, !tbaa !23
72+
br label %for.cond, !dbg !45
73+
74+
for.cond: ; preds = %for.inc, %entry
75+
%1 = load i32, i32* %i, align 4, !dbg !47, !tbaa !23
76+
%2 = load i32*, i32** %A.addr, align 8, !dbg !49, !tbaa !16
77+
%3 = load i32, i32* %2, align 4, !dbg !50, !tbaa !23
78+
%cmp = icmp slt i32 %1, %3, !dbg !51
79+
br i1 %cmp, label %for.body, label %for.cond.cleanup, !dbg !52
80+
81+
for.cond.cleanup: ; preds = %for.cond
82+
%4 = bitcast i32* %i to i8*, !dbg !53
83+
call void @llvm.lifetime.end.p0i8(i64 4, i8* %4) #3, !dbg !53
84+
br label %for.end
85+
86+
for.body: ; preds = %for.cond
87+
%5 = load i32*, i32** %A.addr, align 8, !dbg !54, !tbaa !16
88+
%6 = load i32, i32* %i, align 4, !dbg !55, !tbaa !23
89+
%idxprom = sext i32 %6 to i64, !dbg !54
90+
%arrayidx = getelementptr inbounds i32, i32* %5, i64 %idxprom, !dbg !54
91+
store i32 0, i32* %arrayidx, align 4, !dbg !56, !tbaa !23
92+
br label %for.inc, !dbg !54
93+
94+
for.inc: ; preds = %for.body
95+
%7 = load i32, i32* %i, align 4, !dbg !57, !tbaa !23
96+
%inc = add nsw i32 %7, 1, !dbg !57
97+
store i32 %inc, i32* %i, align 4, !dbg !57, !tbaa !23
98+
br label %for.cond, !dbg !53, !llvm.loop !58
99+
100+
for.end: ; preds = %for.cond.cleanup
101+
ret void, !dbg !60
102+
}
103+
104+
attributes #0 = { nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "denormal-fp-math"="ieee,ieee" "denormal-fp-math-f32"="ieee,ieee" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
105+
attributes #1 = { nounwind readnone speculatable willreturn }
106+
attributes #2 = { argmemonly nounwind willreturn }
107+
attributes #3 = { nounwind }
108+
109+
!llvm.dbg.cu = !{!0}
110+
!llvm.module.flags = !{!3, !4, !5}
111+
!llvm.ident = !{!6}
112+
113+
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 11.0.0 ([email protected]:llvm/llvm-project.git 1d5da8cd30fce1c0a2c2fa6ba656dbfaa36192c8)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
114+
!1 = !DIFile(filename: "various_ir_values.c", directory: "/data/build/llvm-project")
115+
!2 = !{}
116+
!3 = !{i32 7, !"Dwarf Version", i32 4}
117+
!4 = !{i32 2, !"Debug Info Version", i32 3}
118+
!5 = !{i32 1, !"wchar_size", i32 4}
119+
!6 = !{!"clang version 11.0.0 ([email protected]:llvm/llvm-project.git 1d5da8cd30fce1c0a2c2fa6ba656dbfaa36192c8)"}
120+
!7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !8, scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !12)
121+
!8 = !DISubroutineType(types: !9)
122+
!9 = !{null, !10}
123+
!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64)
124+
!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
125+
!12 = !{!13, !14}
126+
!13 = !DILocalVariable(name: "A", arg: 1, scope: !7, file: !1, line: 1, type: !10)
127+
!14 = !DILocalVariable(name: "i", scope: !15, file: !1, line: 3, type: !11)
128+
!15 = distinct !DILexicalBlock(scope: !7, file: !1, line: 3, column: 3)
129+
!16 = !{!17, !17, i64 0}
130+
!17 = !{!"any pointer", !18, i64 0}
131+
!18 = !{!"omnipotent char", !19, i64 0}
132+
!19 = !{!"Simple C/C++ TBAA"}
133+
!20 = !DILocation(line: 1, column: 15, scope: !7)
134+
!21 = !DILocation(line: 3, column: 8, scope: !15)
135+
!22 = !DILocation(line: 3, column: 12, scope: !15)
136+
!23 = !{!24, !24, i64 0}
137+
!24 = !{!"int", !18, i64 0}
138+
!25 = !DILocation(line: 3, column: 19, scope: !26)
139+
!26 = distinct !DILexicalBlock(scope: !15, file: !1, line: 3, column: 3)
140+
!27 = !DILocation(line: 3, column: 24, scope: !26)
141+
!28 = !DILocation(line: 3, column: 23, scope: !26)
142+
!29 = !DILocation(line: 3, column: 21, scope: !26)
143+
!30 = !DILocation(line: 3, column: 3, scope: !15)
144+
!31 = !DILocation(line: 3, column: 3, scope: !26)
145+
!32 = !DILocation(line: 4, column: 5, scope: !26)
146+
!33 = !DILocation(line: 4, column: 7, scope: !26)
147+
!34 = !DILocation(line: 4, column: 10, scope: !26)
148+
!35 = !DILocation(line: 3, column: 27, scope: !26)
149+
!36 = distinct !{!36, !30, !37}
150+
!37 = !DILocation(line: 4, column: 12, scope: !15)
151+
!38 = !DILocation(line: 5, column: 1, scope: !7)
152+
!39 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 7, type: !8, scopeLine: 7, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !40)
153+
!40 = !{!41, !42}
154+
!41 = !DILocalVariable(name: "A", arg: 1, scope: !39, file: !1, line: 7, type: !10)
155+
!42 = !DILocalVariable(name: "i", scope: !43, file: !1, line: 9, type: !11)
156+
!43 = distinct !DILexicalBlock(scope: !39, file: !1, line: 9, column: 3)
157+
!44 = !DILocation(line: 7, column: 15, scope: !39)
158+
!45 = !DILocation(line: 9, column: 8, scope: !43)
159+
!46 = !DILocation(line: 9, column: 12, scope: !43)
160+
!47 = !DILocation(line: 9, column: 19, scope: !48)
161+
!48 = distinct !DILexicalBlock(scope: !43, file: !1, line: 9, column: 3)
162+
!49 = !DILocation(line: 9, column: 24, scope: !48)
163+
!50 = !DILocation(line: 9, column: 23, scope: !48)
164+
!51 = !DILocation(line: 9, column: 21, scope: !48)
165+
!52 = !DILocation(line: 9, column: 3, scope: !43)
166+
!53 = !DILocation(line: 9, column: 3, scope: !48)
167+
!54 = !DILocation(line: 10, column: 5, scope: !48)
168+
!55 = !DILocation(line: 10, column: 7, scope: !48)
169+
!56 = !DILocation(line: 10, column: 10, scope: !48)
170+
!57 = !DILocation(line: 9, column: 27, scope: !48)
171+
!58 = distinct !{!58, !52, !59}
172+
!59 = !DILocation(line: 10, column: 12, scope: !43)
173+
!60 = !DILocation(line: 11, column: 1, scope: !39)

0 commit comments

Comments
 (0)