[llvm-branch-commits] [llvm] [FLMD] Add MDFunctionLocalContext support to update_test_checks (PR #244621)
Stephen Tozer via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Nov 23 06:54:37 PST 2026
https://github.com/SLTozer updated https://github.com/llvm/llvm-project/pull/244621
>From 4437b18d7fd06fe91f638eba71cbc933641f788f Mon Sep 17 00:00:00 2001
From: Stephen Tozer <stephen.tozer at sony.com>
Date: Thu, 19 Nov 2026 15:01:19 +0000
Subject: [PATCH] Add MDFunctionLocalContext support to update_test_checks
The new `!MDFunctionLocalContext` metadata type is unique in that it may
be printed across multiple lines, which causes the update_test_checks
script to only generate checks, and transitively find other metadata, for
the opening line. This patch fixes this by recording multiple lines for
metadata, where the first line ends with '[' and the last line ends with
'])', matching the printed format of `!MDFunctionLocalContext`.
---
.../update_test_checks/Inputs/flmd-context.ll | 68 +++++++++
.../Inputs/flmd-context.ll.all.expected | 133 ++++++++++++++++++
.../Inputs/flmd-context.ll.expected | 126 +++++++++++++++++
.../update_test_checks/flmd-context.test | 12 ++
llvm/utils/UpdateTestChecks/common.py | 51 ++++---
5 files changed, 374 insertions(+), 16 deletions(-)
create mode 100644 llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/flmd-context.ll
create mode 100644 llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/flmd-context.ll.all.expected
create mode 100644 llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/flmd-context.ll.expected
create mode 100644 llvm/test/tools/UpdateTestChecks/update_test_checks/flmd-context.test
diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/flmd-context.ll b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/flmd-context.ll
new file mode 100644
index 00000000000000..ff8384527cf040
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/flmd-context.ll
@@ -0,0 +1,68 @@
+; RUN: opt < %s -S | FileCheck %s
+
+define i32 @foo(i32 %i) !dbg !9 !flmd !12 {
+entry:
+ ret i32 %i
+}
+
+define i32 @baz(i32 %i) !flmd !19 {
+entry:
+ ret i32 %i
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2, !3, !4, !5, !6, !7}
+!llvm.ident = !{!8}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 24.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "test.c", directory: "/")
+!2 = !{i32 7, !"Dwarf Version", i32 5}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = !{i32 8, !"PIC Level", i32 2}
+!5 = !{i32 7, !"PIE Level", i32 2}
+!6 = !{i32 7, !"uwtable", i32 2}
+!7 = !{i32 7, !"frame-pointer", i32 2}
+!8 = !{!"clang version 24.0.0git"}
+!9 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 2, type: !10, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
+!10 = !DISubroutineType(types: !11)
+!11 = !{}
+!12 = distinct !MDFunctionLocalContext(scopes: [
+ !!scope(scope: !9),
+], srcLocs: [
+ !!srcLoc(line: 0, scope: 0),
+ !!srcLoc(line: 2, scope: 0),
+ !!srcLoc(line: 3, scope: 0),
+], inlinedCalls: [
+ !!inlinedCall(srcLoc: 2, inlineeContext: !13),
+ !!inlinedCall(srcLoc: 4, inlinedAt: 0, uniquable: true, inlineeContext: !16),
+ !!inlinedCall(srcLoc: 2, inlineeContext: !12),
+])
+!13 = distinct !MDFunctionLocalContext(scopes: [
+ !!scope(scope: !14),
+ !!scope(scope: !15),
+], srcLocs: [
+ !!srcLoc(line: 0, scope: 0),
+ !!srcLoc(line: 12, scope: 0),
+ !!srcLoc(line: 13, scope: 0),
+ !!srcLoc(line: 14, column: 7, scope: 1),
+ !!srcLoc(line: 15, scope: 1),
+ !!srcLoc(line: 16, column: 12, scope: 0),
+])
+!14 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 12, type: !10, scopeLine: 12, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
+!15 = distinct !DILexicalBlock(scope: !14, file: !1, line: 13)
+!16 = distinct !MDFunctionLocalContext(scopes: [
+ !!scope(scope: !17),
+ !!scope(scope: !18),
+], srcLocs: [
+ !!srcLoc(line: 0, scope: 0),
+ !!srcLoc(line: 22, scope: 0),
+ !!srcLoc(line: 23, scope: 1),
+], inlinedCalls: [
+ !!inlinedCall(srcLoc: 1, inlineeContext: !12),
+])
+!17 = distinct !DISubprogram(name: "qux", scope: !1, file: !1, line: 22, type: !10, scopeLine: 22, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
+!18 = !DILexicalBlock(scope: !17, file: !1, line: 23)
+!19 = distinct !MDFunctionLocalContext(nonDebug: true, inlinedCalls: [
+ !!inlinedCall(inlineeContext: !12),
+ !!inlinedCall(srcLoc: 2, inlinedAt: 0, inlineeContext: !13),
+])
diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/flmd-context.ll.all.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/flmd-context.ll.all.expected
new file mode 100644
index 00000000000000..1a7ca7977b58ec
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/flmd-context.ll.all.expected
@@ -0,0 +1,133 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals all --version 6
+; RUN: opt < %s -S | FileCheck %s
+
+define i32 @foo(i32 %i) !dbg !9 !flmd !12 {
+; CHECK-LABEL: define i32 @foo(
+; CHECK-SAME: i32 [[I:%.*]]) !dbg [[DBG9:![0-9]+]] !flmd [[FLMD12:![0-9]+]] {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: ret i32 [[I]]
+;
+entry:
+ ret i32 %i
+}
+
+define i32 @baz(i32 %i) !flmd !19 {
+; CHECK-LABEL: define i32 @baz(
+; CHECK-SAME: i32 [[I:%.*]]) !flmd [[FLMD19:![0-9]+]] {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: ret i32 [[I]]
+;
+entry:
+ ret i32 %i
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2, !3, !4, !5, !6, !7}
+!llvm.ident = !{!8}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 24.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "test.c", directory: "/")
+!2 = !{i32 7, !"Dwarf Version", i32 5}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = !{i32 8, !"PIC Level", i32 2}
+!5 = !{i32 7, !"PIE Level", i32 2}
+!6 = !{i32 7, !"uwtable", i32 2}
+!7 = !{i32 7, !"frame-pointer", i32 2}
+!8 = !{!"clang version 24.0.0git"}
+!9 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 2, type: !10, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
+!10 = !DISubroutineType(types: !11)
+!11 = !{}
+!12 = distinct !MDFunctionLocalContext(scopes: [
+ !!scope(scope: !9),
+], srcLocs: [
+ !!srcLoc(line: 0, scope: 0),
+ !!srcLoc(line: 2, scope: 0),
+ !!srcLoc(line: 3, scope: 0),
+], inlinedCalls: [
+ !!inlinedCall(srcLoc: 2, inlineeContext: !13),
+ !!inlinedCall(srcLoc: 4, inlinedAt: 0, uniquable: true, inlineeContext: !16),
+ !!inlinedCall(srcLoc: 2, inlineeContext: !12),
+])
+!13 = distinct !MDFunctionLocalContext(scopes: [
+ !!scope(scope: !14),
+ !!scope(scope: !15),
+], srcLocs: [
+ !!srcLoc(line: 0, scope: 0),
+ !!srcLoc(line: 12, scope: 0),
+ !!srcLoc(line: 13, scope: 0),
+ !!srcLoc(line: 14, column: 7, scope: 1),
+ !!srcLoc(line: 15, scope: 1),
+ !!srcLoc(line: 16, column: 12, scope: 0),
+])
+!14 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 12, type: !10, scopeLine: 12, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
+!15 = distinct !DILexicalBlock(scope: !14, file: !1, line: 13)
+!16 = distinct !MDFunctionLocalContext(scopes: [
+ !!scope(scope: !17),
+ !!scope(scope: !18),
+], srcLocs: [
+ !!srcLoc(line: 0, scope: 0),
+ !!srcLoc(line: 22, scope: 0),
+ !!srcLoc(line: 23, scope: 1),
+], inlinedCalls: [
+ !!inlinedCall(srcLoc: 1, inlineeContext: !12),
+])
+!17 = distinct !DISubprogram(name: "qux", scope: !1, file: !1, line: 22, type: !10, scopeLine: 22, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
+!18 = !DILexicalBlock(scope: !17, file: !1, line: 23)
+!19 = distinct !MDFunctionLocalContext(nonDebug: true, inlinedCalls: [
+ !!inlinedCall(inlineeContext: !12),
+ !!inlinedCall(srcLoc: 2, inlinedAt: 0, inlineeContext: !13),
+])
+;.
+; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C11, file: [[META1:![0-9]+]], producer: "{{.*}}clang version {{.*}}", isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly, splitDebugInlining: false, nameTableKind: None)
+; CHECK: [[META1]] = !DIFile(filename: "{{.*}}test.c", directory: {{.*}})
+; CHECK: [[META2:![0-9]+]] = !{i32 7, !"Dwarf Version", i32 5}
+; CHECK: [[META3:![0-9]+]] = !{i32 2, !"Debug Info Version", i32 3}
+; CHECK: [[META4:![0-9]+]] = !{i32 8, !"PIC Level", i32 2}
+; CHECK: [[META5:![0-9]+]] = !{i32 7, !"PIE Level", i32 2}
+; CHECK: [[META6:![0-9]+]] = !{i32 7, !"uwtable", i32 2}
+; CHECK: [[META7:![0-9]+]] = !{i32 7, !"frame-pointer", i32 2}
+; CHECK: [[META8:![0-9]+]] = !{!"{{.*}}clang version {{.*}}"}
+; CHECK: [[DBG9]] = distinct !DISubprogram(name: "foo", scope: [[META1]], file: [[META1]], line: 2, type: [[META10:![0-9]+]], scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: [[META0]])
+; CHECK: [[META10]] = !DISubroutineType(types: [[META11:![0-9]+]])
+; CHECK: [[META11]] = !{}
+; CHECK: [[FLMD12]] = distinct !MDFunctionLocalContext(scopes: [
+; CHECK-NEXT: !!scope(scope: [[DBG9]]),
+; CHECK-NEXT: ], srcLocs: [
+; CHECK-NEXT: !!srcLoc(line: 0, scope: 0),
+; CHECK-NEXT: !!srcLoc(line: 2, scope: 0),
+; CHECK-NEXT: !!srcLoc(line: 3, scope: 0),
+; CHECK-NEXT: ], inlinedCalls: [
+; CHECK-NEXT: !!inlinedCall(srcLoc: 2, inlineeContext: [[META13:![0-9]+]]),
+; CHECK-NEXT: !!inlinedCall(srcLoc: 4, inlinedAt: 0, uniquable: true, inlineeContext: [[META16:![0-9]+]]),
+; CHECK-NEXT: !!inlinedCall(srcLoc: 2, inlineeContext: [[FLMD12]]),
+; CHECK-NEXT: ])
+; CHECK: [[META13]] = distinct !MDFunctionLocalContext(scopes: [
+; CHECK-NEXT: !!scope(scope: [[META14:![0-9]+]]),
+; CHECK-NEXT: !!scope(scope: [[META15:![0-9]+]]),
+; CHECK-NEXT: ], srcLocs: [
+; CHECK-NEXT: !!srcLoc(line: 0, scope: 0),
+; CHECK-NEXT: !!srcLoc(line: 12, scope: 0),
+; CHECK-NEXT: !!srcLoc(line: 13, scope: 0),
+; CHECK-NEXT: !!srcLoc(line: 14, column: 7, scope: 1),
+; CHECK-NEXT: !!srcLoc(line: 15, scope: 1),
+; CHECK-NEXT: !!srcLoc(line: 16, column: 12, scope: 0),
+; CHECK-NEXT: ])
+; CHECK: [[META14]] = distinct !DISubprogram(name: "bar", scope: [[META1]], file: [[META1]], line: 12, type: [[META10]], scopeLine: 12, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: [[META0]])
+; CHECK: [[META15]] = distinct !DILexicalBlock(scope: [[META14]], file: [[META1]], line: 13)
+; CHECK: [[META16]] = distinct !MDFunctionLocalContext(scopes: [
+; CHECK-NEXT: !!scope(scope: [[META17:![0-9]+]]),
+; CHECK-NEXT: !!scope(scope: [[META18:![0-9]+]]),
+; CHECK-NEXT: ], srcLocs: [
+; CHECK-NEXT: !!srcLoc(line: 0, scope: 0),
+; CHECK-NEXT: !!srcLoc(line: 22, scope: 0),
+; CHECK-NEXT: !!srcLoc(line: 23, scope: 1),
+; CHECK-NEXT: ], inlinedCalls: [
+; CHECK-NEXT: !!inlinedCall(srcLoc: 1, inlineeContext: [[FLMD12]]),
+; CHECK-NEXT: ])
+; CHECK: [[META17]] = distinct !DISubprogram(name: "qux", scope: [[META1]], file: [[META1]], line: 22, type: [[META10]], scopeLine: 22, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: [[META0]])
+; CHECK: [[META18]] = !DILexicalBlock(scope: [[META17]], file: [[META1]], line: 23)
+; CHECK: [[FLMD19]] = distinct !MDFunctionLocalContext(nonDebug: true, inlinedCalls: [
+; CHECK-NEXT: !!inlinedCall(inlineeContext: [[FLMD12]]),
+; CHECK-NEXT: !!inlinedCall(srcLoc: 2, inlinedAt: 0, inlineeContext: [[META13]]),
+; CHECK-NEXT: ])
+;.
diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/flmd-context.ll.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/flmd-context.ll.expected
new file mode 100644
index 00000000000000..9beb5446f7d70e
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/flmd-context.ll.expected
@@ -0,0 +1,126 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt < %s -S | FileCheck %s
+
+define i32 @foo(i32 %i) !dbg !9 !flmd !12 {
+; CHECK-LABEL: define i32 @foo(
+; CHECK-SAME: i32 [[I:%.*]]) !dbg [[DBG9:![0-9]+]] !flmd [[FLMD12:![0-9]+]] {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: ret i32 [[I]]
+;
+entry:
+ ret i32 %i
+}
+
+define i32 @baz(i32 %i) !flmd !19 {
+; CHECK-LABEL: define i32 @baz(
+; CHECK-SAME: i32 [[I:%.*]]) !flmd [[FLMD19:![0-9]+]] {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: ret i32 [[I]]
+;
+entry:
+ ret i32 %i
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2, !3, !4, !5, !6, !7}
+!llvm.ident = !{!8}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 24.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "test.c", directory: "/")
+!2 = !{i32 7, !"Dwarf Version", i32 5}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = !{i32 8, !"PIC Level", i32 2}
+!5 = !{i32 7, !"PIE Level", i32 2}
+!6 = !{i32 7, !"uwtable", i32 2}
+!7 = !{i32 7, !"frame-pointer", i32 2}
+!8 = !{!"clang version 24.0.0git"}
+!9 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 2, type: !10, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
+!10 = !DISubroutineType(types: !11)
+!11 = !{}
+!12 = distinct !MDFunctionLocalContext(scopes: [
+ !!scope(scope: !9),
+], srcLocs: [
+ !!srcLoc(line: 0, scope: 0),
+ !!srcLoc(line: 2, scope: 0),
+ !!srcLoc(line: 3, scope: 0),
+], inlinedCalls: [
+ !!inlinedCall(srcLoc: 2, inlineeContext: !13),
+ !!inlinedCall(srcLoc: 4, inlinedAt: 0, uniquable: true, inlineeContext: !16),
+ !!inlinedCall(srcLoc: 2, inlineeContext: !12),
+])
+!13 = distinct !MDFunctionLocalContext(scopes: [
+ !!scope(scope: !14),
+ !!scope(scope: !15),
+], srcLocs: [
+ !!srcLoc(line: 0, scope: 0),
+ !!srcLoc(line: 12, scope: 0),
+ !!srcLoc(line: 13, scope: 0),
+ !!srcLoc(line: 14, column: 7, scope: 1),
+ !!srcLoc(line: 15, scope: 1),
+ !!srcLoc(line: 16, column: 12, scope: 0),
+])
+!14 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 12, type: !10, scopeLine: 12, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
+!15 = distinct !DILexicalBlock(scope: !14, file: !1, line: 13)
+!16 = distinct !MDFunctionLocalContext(scopes: [
+ !!scope(scope: !17),
+ !!scope(scope: !18),
+], srcLocs: [
+ !!srcLoc(line: 0, scope: 0),
+ !!srcLoc(line: 22, scope: 0),
+ !!srcLoc(line: 23, scope: 1),
+], inlinedCalls: [
+ !!inlinedCall(srcLoc: 1, inlineeContext: !12),
+])
+!17 = distinct !DISubprogram(name: "qux", scope: !1, file: !1, line: 22, type: !10, scopeLine: 22, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
+!18 = !DILexicalBlock(scope: !17, file: !1, line: 23)
+!19 = distinct !MDFunctionLocalContext(nonDebug: true, inlinedCalls: [
+ !!inlinedCall(inlineeContext: !12),
+ !!inlinedCall(srcLoc: 2, inlinedAt: 0, inlineeContext: !13),
+])
+;.
+; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C11, file: [[META1:![0-9]+]], producer: "{{.*}}clang version {{.*}}", isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly, splitDebugInlining: false, nameTableKind: None)
+; CHECK: [[META1]] = !DIFile(filename: "{{.*}}test.c", directory: {{.*}})
+; CHECK: [[DBG9]] = distinct !DISubprogram(name: "foo", scope: [[META1]], file: [[META1]], line: 2, type: [[META10:![0-9]+]], scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: [[META0]])
+; CHECK: [[META10]] = !DISubroutineType(types: [[META11:![0-9]+]])
+; CHECK: [[META11]] = !{}
+; CHECK: [[FLMD12]] = distinct !MDFunctionLocalContext(scopes: [
+; CHECK-NEXT: !!scope(scope: [[DBG9]]),
+; CHECK-NEXT: ], srcLocs: [
+; CHECK-NEXT: !!srcLoc(line: 0, scope: 0),
+; CHECK-NEXT: !!srcLoc(line: 2, scope: 0),
+; CHECK-NEXT: !!srcLoc(line: 3, scope: 0),
+; CHECK-NEXT: ], inlinedCalls: [
+; CHECK-NEXT: !!inlinedCall(srcLoc: 2, inlineeContext: [[META13:![0-9]+]]),
+; CHECK-NEXT: !!inlinedCall(srcLoc: 4, inlinedAt: 0, uniquable: true, inlineeContext: [[META16:![0-9]+]]),
+; CHECK-NEXT: !!inlinedCall(srcLoc: 2, inlineeContext: [[FLMD12]]),
+; CHECK-NEXT: ])
+; CHECK: [[META13]] = distinct !MDFunctionLocalContext(scopes: [
+; CHECK-NEXT: !!scope(scope: [[META14:![0-9]+]]),
+; CHECK-NEXT: !!scope(scope: [[META15:![0-9]+]]),
+; CHECK-NEXT: ], srcLocs: [
+; CHECK-NEXT: !!srcLoc(line: 0, scope: 0),
+; CHECK-NEXT: !!srcLoc(line: 12, scope: 0),
+; CHECK-NEXT: !!srcLoc(line: 13, scope: 0),
+; CHECK-NEXT: !!srcLoc(line: 14, column: 7, scope: 1),
+; CHECK-NEXT: !!srcLoc(line: 15, scope: 1),
+; CHECK-NEXT: !!srcLoc(line: 16, column: 12, scope: 0),
+; CHECK-NEXT: ])
+; CHECK: [[META14]] = distinct !DISubprogram(name: "bar", scope: [[META1]], file: [[META1]], line: 12, type: [[META10]], scopeLine: 12, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: [[META0]])
+; CHECK: [[META15]] = distinct !DILexicalBlock(scope: [[META14]], file: [[META1]], line: 13)
+; CHECK: [[META16]] = distinct !MDFunctionLocalContext(scopes: [
+; CHECK-NEXT: !!scope(scope: [[META17:![0-9]+]]),
+; CHECK-NEXT: !!scope(scope: [[META18:![0-9]+]]),
+; CHECK-NEXT: ], srcLocs: [
+; CHECK-NEXT: !!srcLoc(line: 0, scope: 0),
+; CHECK-NEXT: !!srcLoc(line: 22, scope: 0),
+; CHECK-NEXT: !!srcLoc(line: 23, scope: 1),
+; CHECK-NEXT: ], inlinedCalls: [
+; CHECK-NEXT: !!inlinedCall(srcLoc: 1, inlineeContext: [[FLMD12]]),
+; CHECK-NEXT: ])
+; CHECK: [[META17]] = distinct !DISubprogram(name: "qux", scope: [[META1]], file: [[META1]], line: 22, type: [[META10]], scopeLine: 22, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: [[META0]])
+; CHECK: [[META18]] = !DILexicalBlock(scope: [[META17]], file: [[META1]], line: 23)
+; CHECK: [[FLMD19]] = distinct !MDFunctionLocalContext(nonDebug: true, inlinedCalls: [
+; CHECK-NEXT: !!inlinedCall(inlineeContext: [[FLMD12]]),
+; CHECK-NEXT: !!inlinedCall(srcLoc: 2, inlinedAt: 0, inlineeContext: [[META13]]),
+; CHECK-NEXT: ])
+;.
diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/flmd-context.test b/llvm/test/tools/UpdateTestChecks/update_test_checks/flmd-context.test
new file mode 100644
index 00000000000000..c0be4117167e3d
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/flmd-context.test
@@ -0,0 +1,12 @@
+# Verify that update_test_checks can generate checks for an
+# !MDFunctionLocalContext, which is printed across multiple lines.
+# RUN: cp -f %S/Inputs/flmd-context.ll %t.ll && %update_test_checks %t.ll --version 6 --check-globals smart
+# RUN: diff -u %t.ll %S/Inputs/flmd-context.ll.expected
+
+# Verify script is idempotent
+# RUN: %update_test_checks %t.ll --version 6 --check-globals smart
+# RUN: diff -u %t.ll %S/Inputs/flmd-context.ll.expected
+
+# Verify it also works for check-globals all
+# RUN: cp -f %S/Inputs/flmd-context.ll %t.ll && %update_test_checks %t.ll --version 6 --check-globals all
+# RUN: diff -u %t.ll %S/Inputs/flmd-context.ll.all.expected
diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py
index 290035c68f12fb..7724972d75f746 100644
--- a/llvm/utils/UpdateTestChecks/common.py
+++ b/llvm/utils/UpdateTestChecks/common.py
@@ -1435,6 +1435,7 @@ def make_ir_generalizer(version, no_meta_details):
interlaced_with_previous=True,
),
NamelessValue(r"DBG", "!", r"!dbg ", r"![0-9]+", None),
+ NamelessValue(r"FLMD", "!", r"!flmd ", r"![0-9]+", None),
NamelessValue(r"DIASSIGNID", "!", r"!DIAssignID ", r"![0-9]+", None),
NamelessValue(r"PROF", "!", r"!prof ", r"![0-9]+", None),
NamelessValue(r"TBAA", "!", r"!tbaa ", r"![0-9]+", None),
@@ -2532,7 +2533,17 @@ def build_global_values_dictionary(glob_val_dict, raw_tool_output, prefixes, gin
# Attach the substring's start index so that CHECK lines
# can be sorted properly even if they are matched by different nameless values.
# This is relevant for GLOB and GLOBNAMED since they may appear interlaced.
- lines.append((m.start(), m.group(0)))
+ if not m.group(0).endswith('['):
+ lines.append((m.start(), [m.group(0)]))
+ else:
+ # For FLMD, we actually have many lines for a single entry, and must include all of them.
+ succeeding_text: str = raw_tool_output[m.start():]
+ entry_lines = []
+ for line in succeeding_text.splitlines():
+ entry_lines.append(line)
+ if line.endswith('])'):
+ break
+ lines.append((m.start(), entry_lines))
for prefix in prefixes:
if glob_val_dict[prefix] is None:
@@ -2561,7 +2572,7 @@ def filter_globals_according_to_preference(
# attribute sets are usually better checked by --check-attributes
return []
- def extract(line, nv):
+ def extract(lines, nv):
p = (
"^"
+ nv.ir_prefix
@@ -2571,8 +2582,12 @@ def extract(line, nv):
+ nv.global_ir_rhs_regexp
+ ")"
)
- match = re.match(p, line)
- return (match.group(1), re.findall(nv.ir_regexp, match.group(2)))
+ main_line = lines[0]
+ match = re.match(p, main_line)
+ found_matches = re.findall(nv.ir_regexp, match.group(2))
+ for extra_line in lines[1:]:
+ found_matches.extend(re.findall(nv.ir_regexp, extra_line))
+ return (match.group(1), found_matches)
transitively_visible = set()
contains_refs_to = {}
@@ -2588,17 +2603,17 @@ def add(var):
for x in contains_refs_to[var]:
add(x)
- for i, line in global_val_lines_w_index:
- (var, refs) = extract(line, nameless_value)
+ for i, lines in global_val_lines_w_index:
+ (var, refs) = extract(lines, nameless_value)
contains_refs_to[var] = refs
for var, check_key in global_vars_seen:
if check_key != nameless_value.check_key:
continue
add(var)
return [
- (i, line)
- for i, line in global_val_lines_w_index
- if extract(line, nameless_value)[0] in transitively_visible
+ (i, lines)
+ for i, lines in global_val_lines_w_index
+ if extract(lines, nameless_value)[0] in transitively_visible
]
@@ -2684,19 +2699,19 @@ def add_global_checks(
nameless_value,
global_check_setting,
)
- for i, line in lines_w_index:
+ for i, lines in lines_w_index:
if _global_value_regex:
matched = False
for regex in _global_value_regex:
- if re.match("^@" + regex + " = ", line) or re.match(
- "^!" + regex + " = ", line
+ if re.match("^@" + regex + " = ", lines[0]) or re.match(
+ "^!" + regex + " = ", lines[0]
):
matched = True
break
if not matched:
continue
- [new_line] = generalize_check_lines(
- [line],
+ new_lines = generalize_check_lines(
+ lines,
ginfo,
{},
global_vars_seen,
@@ -2704,9 +2719,13 @@ def add_global_checks(
preserve_names,
unstable_globals_only=True,
)
- new_line = filter_unstable_metadata(new_line)
- check_line = "%s %s: %s" % (comment_marker, checkprefix, new_line)
+ new_lines[0] = filter_unstable_metadata(new_lines[0])
+ check_line = "%s %s: %s" % (comment_marker, checkprefix, new_lines[0])
check_lines.append((i, check_line))
+ for idx, new_line in enumerate(new_lines[1:]):
+ check_line = "%s %s-NEXT: %s" % (comment_marker, checkprefix, new_line)
+ # This is an incorrect idx in terms of actual file position, but correct in terms of ordering.
+ check_lines.append((i + idx + 1, check_line))
if not check_lines:
continue
More information about the llvm-branch-commits
mailing list