Skip to content

Commit 8ec7a84

Browse files
slinder1github-actions[bot]
authored andcommitted
Automerge: update_test_checks: Relax DIFile filename checks (#135692)
Avoid baking in absolute paths in check lines generated for DIFile metadata. Generated test checks cannot be sensitive to absolute paths anyway, as those vary with the environment, but there could be situations where some sensitivity to partial paths is required for certain tests. This implementation just assumes such tests aren't worth the effort to support, but it could be supported in the future. This is most useful for update_cc_test_checks with debug info enabled, where the test writer cannot manipulate the paths within the generated IR directly.
2 parents 401713a + e78b763 commit 8ec7a84

File tree

6 files changed

+88
-3
lines changed

6 files changed

+88
-3
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
; RUN: opt < %s -S | FileCheck %s
2+
3+
source_filename = "/llvm-project/foo.c"
4+
5+
define dso_local void @f() !dbg !10 {
6+
entry:
7+
ret void, !dbg !14
8+
}
9+
10+
!llvm.dbg.cu = !{!0}
11+
!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8}
12+
!llvm.ident = !{!9}
13+
14+
!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
15+
!1 = !DIFile(filename: "/llvm-project/foo.c", directory: "/llvm-project")
16+
!2 = !{i32 7, !"Dwarf Version", i32 5}
17+
!3 = !{i32 2, !"Debug Info Version", i32 3}
18+
!4 = !{i32 1, !"wchar_size", i32 4}
19+
!5 = !{i32 8, !"PIC Level", i32 2}
20+
!6 = !{i32 7, !"PIE Level", i32 2}
21+
!7 = !{i32 7, !"uwtable", i32 2}
22+
!8 = !{i32 7, !"frame-pointer", i32 2}
23+
!9 = !{!"clang"}
24+
!10 = distinct !DISubprogram(name: "f", scope: !11, file: !11, line: 1, type: !12, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !0)
25+
!11 = !DIFile(filename: "foo.c", directory: "/llvm-project")
26+
!12 = !DISubroutineType(types: !13)
27+
!13 = !{null}
28+
!14 = !DILocation(line: 1, column: 11, scope: !10)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals
2+
; RUN: opt < %s -S | FileCheck %s
3+
4+
source_filename = "/llvm-project/foo.c"
5+
6+
define dso_local void @f() !dbg !10 {
7+
; CHECK-LABEL: @f(
8+
; CHECK-NEXT: entry:
9+
; CHECK-NEXT: ret void, !dbg [[DBG14:![0-9]+]]
10+
;
11+
entry:
12+
ret void, !dbg !14
13+
}
14+
15+
!llvm.dbg.cu = !{!0}
16+
!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8}
17+
!llvm.ident = !{!9}
18+
19+
!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
20+
!1 = !DIFile(filename: "/llvm-project/foo.c", directory: "/llvm-project")
21+
!2 = !{i32 7, !"Dwarf Version", i32 5}
22+
!3 = !{i32 2, !"Debug Info Version", i32 3}
23+
!4 = !{i32 1, !"wchar_size", i32 4}
24+
!5 = !{i32 8, !"PIC Level", i32 2}
25+
!6 = !{i32 7, !"PIE Level", i32 2}
26+
!7 = !{i32 7, !"uwtable", i32 2}
27+
!8 = !{i32 7, !"frame-pointer", i32 2}
28+
!9 = !{!"clang"}
29+
!10 = distinct !DISubprogram(name: "f", scope: !11, file: !11, line: 1, type: !12, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !0)
30+
!11 = !DIFile(filename: "foo.c", directory: "/llvm-project")
31+
!12 = !DISubroutineType(types: !13)
32+
!13 = !{null}
33+
!14 = !DILocation(line: 1, column: 11, scope: !10)
34+
;.
35+
; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C11, file: [[META1:![0-9]+]], producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
36+
; CHECK: [[META1]] = !DIFile(filename: "{{.*}}foo.c", directory: {{.*}})
37+
; CHECK: [[META2:![0-9]+]] = !{i32 7, !"Dwarf Version", i32 5}
38+
; CHECK: [[META3:![0-9]+]] = !{i32 2, !"Debug Info Version", i32 3}
39+
; CHECK: [[META4:![0-9]+]] = !{i32 1, !"wchar_size", i32 4}
40+
; CHECK: [[META5:![0-9]+]] = !{i32 8, !"PIC Level", i32 2}
41+
; CHECK: [[META6:![0-9]+]] = !{i32 7, !"PIE Level", i32 2}
42+
; CHECK: [[META7:![0-9]+]] = !{i32 7, !"uwtable", i32 2}
43+
; CHECK: [[META8:![0-9]+]] = !{i32 7, !"frame-pointer", i32 2}
44+
; CHECK: [[META9:![0-9]+]] = !{!"clang"}
45+
; CHECK: [[META10:![0-9]+]] = distinct !DISubprogram(name: "f", scope: [[META11:![0-9]+]], file: [[META11]], line: 1, type: [[META12:![0-9]+]], scopeLine: 1, spFlags: DISPFlagDefinition, unit: [[META0]])
46+
; CHECK: [[META11]] = !DIFile(filename: "{{.*}}foo.c", directory: {{.*}})
47+
; CHECK: [[META12]] = !DISubroutineType(types: [[META13:![0-9]+]])
48+
; CHECK: [[META13]] = !{null}
49+
; CHECK: [[DBG14]] = !DILocation(line: 1, column: 11, scope: [[META10]])
50+
;.

llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/various_ir_values_dbgrecords.ll.funcsig.globals.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ attributes #2 = { nounwind }
244244
; CHECK: attributes #[[ATTR2]] = { nounwind }
245245
;.
246246
; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C99, file: [[META1:![0-9]+]], producer: "{{.*}}clang version {{.*}}", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: [[META2:![0-9]+]], splitDebugInlining: false, nameTableKind: None)
247-
; CHECK: [[META1]] = !DIFile(filename: "various_ir_values.c", directory: {{.*}})
247+
; CHECK: [[META1]] = !DIFile(filename: "{{.*}}various_ir_values.c", directory: {{.*}})
248248
; CHECK: [[META2]] = !{}
249249
; CHECK: [[META3:![0-9]+]] = !{i32 7, !"Dwarf Version", i32 4}
250250
; CHECK: [[META4:![0-9]+]] = !{i32 2, !"Debug Info Version", i32 3}

llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/various_ir_values_dbgrecords.ll.funcsig.transitiveglobals.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ attributes #2 = { nounwind }
238238
!62 = !DILocation(line: 11, column: 1, scope: !41)
239239
;.
240240
; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C99, file: [[META1:![0-9]+]], producer: "{{.*}}clang version {{.*}}", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: [[META2:![0-9]+]], splitDebugInlining: false, nameTableKind: None)
241-
; CHECK: [[META1]] = !DIFile(filename: "various_ir_values.c", directory: {{.*}})
241+
; CHECK: [[META1]] = !DIFile(filename: "{{.*}}various_ir_values.c", directory: {{.*}})
242242
; CHECK: [[META2]] = !{}
243243
; CHECK: [[META7:![0-9]+]] = distinct !DISubprogram(name: "foo", scope: [[META1]], file: [[META1]], line: 1, type: [[META8:![0-9]+]], scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]], retainedNodes: [[META12:![0-9]+]])
244244
; CHECK: [[META8]] = !DISubroutineType(types: [[META9:![0-9]+]])
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Test that update_test_checks.py is not sensitive to absolute paths in
2+
## DIFile's filename field.
3+
# RUN: cp -f %S/Inputs/difile_absolute_filenames.ll %t.ll && %update_test_checks %t.ll --check-globals
4+
# RUN: diff -u %t.ll %S/Inputs/difile_absolute_filenames.ll.expected
5+
## Check that running the script again does not change the result:
6+
# RUN: %update_test_checks %t.ll --check-globals
7+
# RUN: diff -u %t.ll %S/Inputs/difile_absolute_filenames.ll.expected

llvm/utils/UpdateTestChecks/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2358,7 +2358,7 @@ def add(var):
23582358
r"(?<=\")(.+ )?(\w+ version )[\d.]+(?:[^\" ]*)(?: \([^)]+\))?",
23592359
r"{{.*}}\2{{.*}}",
23602360
), # preface with glob also, to capture optional CLANG_VENDOR
2361-
(r'(!DIFile\(filename: ".+", directory: )".+"', r"\1{{.*}}"),
2361+
(r'(!DIFile\(filename: ")(.+/)?([^/]+", directory: )".+"', r"\1{{.*}}\3{{.*}}"),
23622362
]
23632363
METADATA_FILTERS_RE = [(re.compile(f), r) for (f, r) in METADATA_FILTERS]
23642364

0 commit comments

Comments
 (0)