[Mlir-commits] [llvm] [mlir] [DebugInfo] Enforce DISubprogram type as required in LLParser (PR #196299)

Jiang Ning llvmlistbot at llvm.org
Thu May 7 06:18:00 PDT 2026


https://github.com/JiangNingHX updated https://github.com/llvm/llvm-project/pull/196299

>From 2cacd817d9fd0e9b5a127269779c8df40ead89cf Mon Sep 17 00:00:00 2001
From: JiangNing <jiangninghx at foxmail.com>
Date: Thu, 7 May 2026 18:35:39 +0800
Subject: [PATCH 1/2] [DebugInfo] Enforce DISubprogram type as required in
 LLParser

Add a parse-time check so that the LLParser treats the `type:` field of
DISubprogram as required and non-null, producing a clear parse-time
error ("missing required field 'type'" / "'type' cannot be null") in
addition to the existing verifier check added in #194556.

Update existing tests to supply a minimal valid type field where they
are not intentionally testing malformed debug info.
---
 llvm/lib/AsmParser/LLParser.cpp               |  2 +-
 .../Analysis/CostModel/X86/free-intrinsics.ll |  4 +-
 .../CostModel/free-intrinsics-datalayout.ll   |  4 +-
 .../CostModel/free-intrinsics-no_info.ll      |  4 +-
 .../Assembler/disubprogram-type-required.ll   | 29 ++++++++++++++
 .../drop-debug-info-nonzero-alloca.ll         |  4 +-
 llvm/test/Assembler/invalid-diflag-bad.ll     |  4 +-
 ...invalid-disubprogram-uniqued-definition.ll |  4 +-
 .../AArch64/GlobalISel/fconstant-dbg-loc.ll   |  4 +-
 .../sdag-no-typesize-warnings-regandsizes.ll  |  4 +-
 .../CodeGen/AArch64/selectiondag-order.ll     |  4 +-
 .../test/CodeGen/AMDGPU/simplify-libcalls2.ll |  4 +-
 llvm/test/CodeGen/ARM/2009-10-16-Scope.ll     |  4 +-
 llvm/test/CodeGen/ARM/analyze-branch-bkpt.ll  |  8 ++--
 llvm/test/CodeGen/Generic/dbg_value.ll        |  4 +-
 llvm/test/CodeGen/MIR/X86/fixed-stack-di.mir  |  4 +-
 .../MIR/X86/invalid-metadata-node-type.mir    |  4 +-
 .../CodeGen/RISCV/rvv/get-vlen-debugloc.mir   |  4 +-
 .../test/CodeGen/WebAssembly/lower-em-sjlj.ll |  4 +-
 llvm/test/CodeGen/X86/2009-10-16-Scope.ll     |  4 +-
 .../CodeGen/X86/AMX/amx-ldtilecfg-insert.ll   |  4 +-
 .../regbankselect-dbg-value-physreg-crash.mir |  4 +-
 llvm/test/CodeGen/X86/StackColoring-dbg.ll    |  4 +-
 llvm/test/CodeGen/X86/addrsig.ll              |  6 ++-
 llvm/test/CodeGen/X86/dbg-changes-codegen.ll  |  4 +-
 .../X86/frame-lowering-debug-intrinsic-2.ll   |  4 +-
 .../X86/frame-lowering-debug-intrinsic.ll     |  6 ++-
 llvm/test/CodeGen/X86/lrshrink.ll             |  4 +-
 .../X86/machine-trace-metrics-crash.ll        |  4 +-
 llvm/test/CodeGen/X86/opt_phis.mir            |  4 +-
 llvm/test/CodeGen/X86/pr149841.ll             |  5 ++-
 llvm/test/CodeGen/X86/pr57673.mir             |  4 +-
 .../X86/selectiondag-dbgvalue-null-crash.ll   |  4 +-
 llvm/test/CodeGen/X86/selectiondag-order.ll   |  4 +-
 .../DebugInfo/AArch64/abstract-sp-unit.ll     |  4 +-
 .../AArch64/merge-locations-legalizer.mir     |  4 +-
 .../Generic/split-dwarf-local-import2.ll      |  6 +--
 .../X86/regcoalescing-clears-dead-dbgvals.mir |  4 +-
 .../DebugInfo/X86/empty-struct-no-crash.ll    |  6 ++-
 .../LTO/X86/Inputs/strip-debug-info-bar.ll    |  5 ++-
 llvm/test/LTO/X86/Inputs/type-mapping-bug2.ll |  4 +-
 llvm/test/LTO/X86/Inputs/type-mapping-bug3.ll |  4 +-
 llvm/test/LTO/X86/pr38046.ll                  |  4 +-
 llvm/test/LTO/X86/type-mapping-bug2.ll        |  5 ++-
 llvm/test/Linker/2009-09-03-mdnode.ll         |  4 +-
 llvm/test/Linker/2009-09-03-mdnode2.ll        |  4 +-
 llvm/test/Linker/odr.ll                       |  4 +-
 llvm/test/Other/dropped-var-stats.ll          |  8 ++--
 .../dbg-declare-discriminator.ll              |  8 ++--
 .../test/Transforms/GlobalDCE/global_ctors.ll |  4 +-
 .../Transforms/Inline/ignore-debug-info.ll    |  4 +-
 .../debuginfo-scalable-typesize.ll            |  4 +-
 .../Transforms/LoopStrengthReduce/pr12018.ll  |  4 +-
 llvm/test/Transforms/ObjCARC/basic.ll         |  4 +-
 llvm/test/Transforms/SampleProfile/nodebug.ll |  4 +-
 llvm/test/Transforms/SampleProfile/summary.ll |  6 ++-
 .../SimplifyCFG/X86/sink-common-code.ll       |  4 +-
 .../preserve-llvm-loop-metadata.ll            |  4 +-
 llvm/test/Transforms/Util/store-first-op.ll   |  4 +-
 .../WholeProgramDevirt/devirt-metadata.ll     | 11 +++---
 llvm/test/Verifier/DISubprogram-type.ll       | 39 ++++++-------------
 llvm/test/Verifier/RemoveDI/blockbyref.ll     |  4 +-
 .../test/Verifier/RemoveDI/fnarg-debuginfo.ll |  4 +-
 .../RemoveDI/llvm.dbg.declare-address.ll      |  4 +-
 .../RemoveDI/llvm.dbg.declare-expression.ll   |  4 +-
 .../RemoveDI/llvm.dbg.declare-variable.ll     |  4 +-
 .../llvm.dbg.intrinsic-dbg-attachment.ll      |  6 ++-
 .../RemoveDI/llvm.dbg.value-expression.ll     |  4 +-
 .../Verifier/RemoveDI/llvm.dbg.value-value.ll |  4 +-
 .../RemoveDI/llvm.dbg.value-variable.ll       |  4 +-
 llvm/test/Verifier/blockbyref.ll              |  4 +-
 llvm/test/Verifier/dbg-difile-crash.ll        |  4 +-
 llvm/test/Verifier/dbg-invalid-retaintypes.ll |  4 +-
 llvm/test/Verifier/dbg-line-without-file.ll   |  4 +-
 llvm/test/Verifier/dbg.ll                     |  4 +-
 llvm/test/Verifier/fnarg-debuginfo.ll         |  4 +-
 llvm/test/Verifier/func-dbg.ll                |  6 ++-
 .../test/Verifier/llvm.dbg.declare-address.ll |  4 +-
 .../Verifier/llvm.dbg.declare-expression.ll   |  4 +-
 .../Verifier/llvm.dbg.declare-variable.ll     |  4 +-
 .../llvm.dbg.intrinsic-dbg-attachment.ll      |  6 ++-
 .../Verifier/llvm.dbg.value-expression.ll     |  4 +-
 llvm/test/Verifier/llvm.dbg.value-value.ll    |  4 +-
 llvm/test/Verifier/llvm.dbg.value-variable.ll |  4 +-
 llvm/test/Verifier/llvm.loop.ll               |  6 ++-
 llvm/test/Verifier/local-import-in-cu.ll      |  4 +-
 llvm/test/Verifier/metadata-function-dbg.ll   |  6 ++-
 llvm/test/Verifier/pr34325.ll                 |  4 +-
 88 files changed, 314 insertions(+), 138 deletions(-)
 create mode 100644 llvm/test/Assembler/disubprogram-type-required.ll

diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 820f64bf30ba7..dd11661e75f12 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -6201,7 +6201,7 @@ bool LLParser::parseDISubprogram(MDNode *&Result, bool IsDistinct) {
   OPTIONAL(linkageName, MDStringField, );                                      \
   OPTIONAL(file, MDField, );                                                   \
   OPTIONAL(line, LineField, );                                                 \
-  OPTIONAL(type, MDField, );                                                   \
+  REQUIRED(type, MDField, (/* AllowNull */ false));                            \
   OPTIONAL(isLocal, MDBoolField, );                                            \
   OPTIONAL(isDefinition, MDBoolField, (true));                                 \
   OPTIONAL(scopeLine, LineField, );                                            \
diff --git a/llvm/test/Analysis/CostModel/X86/free-intrinsics.ll b/llvm/test/Analysis/CostModel/X86/free-intrinsics.ll
index cef960d3bcd30..773ef494a51b6 100644
--- a/llvm/test/Analysis/CostModel/X86/free-intrinsics.ll
+++ b/llvm/test/Analysis/CostModel/X86/free-intrinsics.ll
@@ -76,7 +76,7 @@ declare void @llvm.var.annotation(ptr, ptr, ptr, i32, ptr)
 !llvm.module.flags = !{!7}
 
 !0 = !DILocalVariable(scope: !1)
-!1 = distinct !DISubprogram(name: "dummy", line: 79, isLocal: true, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, file: !3, unit: !9)
+!1 = distinct !DISubprogram(name: "dummy", line: 79, isLocal: true, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, file: !3, unit: !9, type: !12)
 !2 = !DILabel(scope: !1, name: "label", file: !3, line: 7)
 !3 = !DIFile(filename: "debug-label.c", directory: "./")
 !4 = !{ !5 }
@@ -86,3 +86,5 @@ declare void @llvm.var.annotation(ptr, ptr, ptr, i32, ptr)
 !8 = !DILocation(line: 0, scope: !1)
 !9 = distinct !DICompileUnit(language: DW_LANG_C11, file: !3, producer: "clang")
 !10 = distinct !DIAssignID()
+!11 = !{null}
+!12 = !DISubroutineType(types: !11)
diff --git a/llvm/test/Analysis/CostModel/free-intrinsics-datalayout.ll b/llvm/test/Analysis/CostModel/free-intrinsics-datalayout.ll
index 2acc8e8cf4e20..f2117123ab8eb 100644
--- a/llvm/test/Analysis/CostModel/free-intrinsics-datalayout.ll
+++ b/llvm/test/Analysis/CostModel/free-intrinsics-datalayout.ll
@@ -84,7 +84,7 @@ declare void @llvm.var.annotation(ptr, ptr, ptr, i32, ptr)
 !llvm.module.flags = !{!7}
 
 !0 = !DILocalVariable(scope: !1)
-!1 = distinct !DISubprogram(name: "dummy", line: 79, isLocal: true, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, file: !3, unit: !9)
+!1 = distinct !DISubprogram(name: "dummy", line: 79, isLocal: true, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, file: !3, unit: !9, type: !12)
 !2 = !DILabel(scope: !1, name: "label", file: !3, line: 7)
 !3 = !DIFile(filename: "debug-label.c", directory: "./")
 !4 = !{ !5 }
@@ -94,3 +94,5 @@ declare void @llvm.var.annotation(ptr, ptr, ptr, i32, ptr)
 !8 = !DILocation(line: 0, scope: !1)
 !9 = distinct !DICompileUnit(language: DW_LANG_C11, file: !3, producer: "clang")
 !10 = distinct !DIAssignID()
+!11 = !{null}
+!12 = !DISubroutineType(types: !11)
diff --git a/llvm/test/Analysis/CostModel/free-intrinsics-no_info.ll b/llvm/test/Analysis/CostModel/free-intrinsics-no_info.ll
index 7f002d0ee88e4..e454f110e0ee3 100644
--- a/llvm/test/Analysis/CostModel/free-intrinsics-no_info.ll
+++ b/llvm/test/Analysis/CostModel/free-intrinsics-no_info.ll
@@ -82,7 +82,7 @@ declare void @llvm.var.annotation(ptr, ptr, ptr, i32, ptr)
 !llvm.module.flags = !{!7}
 
 !0 = !DILocalVariable(scope: !1)
-!1 = distinct !DISubprogram(name: "dummy", line: 79, isLocal: true, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, file: !3, unit: !9)
+!1 = distinct !DISubprogram(name: "dummy", line: 79, isLocal: true, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, file: !3, unit: !9, type: !12)
 !2 = !DILabel(scope: !1, name: "label", file: !3, line: 7)
 !3 = !DIFile(filename: "debug-label.c", directory: "./")
 !4 = !{ !5 }
@@ -92,3 +92,5 @@ declare void @llvm.var.annotation(ptr, ptr, ptr, i32, ptr)
 !8 = !DILocation(line: 0, scope: !1)
 !9 = distinct !DICompileUnit(language: DW_LANG_C11, file: !3, producer: "clang")
 !10 = distinct !DIAssignID()
+!11 = !{null}
+!12 = !DISubroutineType(types: !11)
diff --git a/llvm/test/Assembler/disubprogram-type-required.ll b/llvm/test/Assembler/disubprogram-type-required.ll
new file mode 100644
index 0000000000000..65fd19a364c8d
--- /dev/null
+++ b/llvm/test/Assembler/disubprogram-type-required.ll
@@ -0,0 +1,29 @@
+; Test that LLParser rejects DISubprogram with missing or null 'type' field.
+; These are parse-time errors, not verifier errors. See issue #186557.
+;
+; RUN: split-file %s %t
+; RUN: not llvm-as %t/missing.ll -disable-output 2>&1 | FileCheck %s --check-prefix=MISSING
+; RUN: not llvm-as %t/null.ll    -disable-output 2>&1 | FileCheck %s --check-prefix=NULL
+;
+; MISSING: missing required field 'type'
+; NULL: 'type' cannot be null
+
+;--- missing.ll
+define void @f() !dbg !4 { ret void }
+!llvm.dbg.cu       = !{!0}
+!llvm.module.flags = !{!3}
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, emissionKind: FullDebug)
+!1 = !DIFile(filename: "x.c", directory: "/")
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 1,
+     scopeLine: 1, spFlags: DISPFlagDefinition, unit: !0)
+
+;--- null.ll
+define void @f() !dbg !4 { ret void }
+!llvm.dbg.cu       = !{!0}
+!llvm.module.flags = !{!3}
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, emissionKind: FullDebug)
+!1 = !DIFile(filename: "x.c", directory: "/")
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 1,
+     scopeLine: 1, spFlags: DISPFlagDefinition, unit: !0, type: null)
diff --git a/llvm/test/Assembler/drop-debug-info-nonzero-alloca.ll b/llvm/test/Assembler/drop-debug-info-nonzero-alloca.ll
index c8b235757afba..7bb61601747b4 100644
--- a/llvm/test/Assembler/drop-debug-info-nonzero-alloca.ll
+++ b/llvm/test/Assembler/drop-debug-info-nonzero-alloca.ll
@@ -25,4 +25,6 @@ declare void @llvm.dbg.value(metadata, metadata, metadata)
 
 !llvm.module.flags = !{!0}
 !0 = !{i32 2, !"Debug Info Version", i32 3}
-!1 = distinct !DISubprogram(name: "foo")
+!1 = distinct !DISubprogram(name: "foo", type: !3)
+!2 = !{null}
+!3 = !DISubroutineType(types: !2)
diff --git a/llvm/test/Assembler/invalid-diflag-bad.ll b/llvm/test/Assembler/invalid-diflag-bad.ll
index cde59f6ce6674..0c5ec6e3a630a 100644
--- a/llvm/test/Assembler/invalid-diflag-bad.ll
+++ b/llvm/test/Assembler/invalid-diflag-bad.ll
@@ -1,4 +1,6 @@
 ; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
 
 ; CHECK: <stdin>:[[@LINE+1]]:27: error: invalid debug info flag 'DIFlagUnknown'
-!0 = !DISubprogram(flags: DIFlagUnknown)
+!0 = !DISubprogram(flags: DIFlagUnknown, type: !2)
+!1 = !{null}
+!2 = !DISubroutineType(types: !1)
diff --git a/llvm/test/Assembler/invalid-disubprogram-uniqued-definition.ll b/llvm/test/Assembler/invalid-disubprogram-uniqued-definition.ll
index 6641e6dc21d72..2d406d5df2b1c 100644
--- a/llvm/test/Assembler/invalid-disubprogram-uniqued-definition.ll
+++ b/llvm/test/Assembler/invalid-disubprogram-uniqued-definition.ll
@@ -1,4 +1,6 @@
 ; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
 
 ; CHECK: <stdin>:[[@LINE+1]]:6: error: missing 'distinct', required for !DISubprogram that is a Definition
-!0 = !DISubprogram(isDefinition: true)
+!0 = !DISubprogram(isDefinition: true, type: !2)
+!1 = !{null}
+!2 = !DISubroutineType(types: !1)
diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/fconstant-dbg-loc.ll b/llvm/test/CodeGen/AArch64/GlobalISel/fconstant-dbg-loc.ll
index 6281c2f5c0a78..4661a0132afc0 100644
--- a/llvm/test/CodeGen/AArch64/GlobalISel/fconstant-dbg-loc.ll
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/fconstant-dbg-loc.ll
@@ -21,5 +21,7 @@ define float @main() #0 !dbg !14 {
 !11 = !{i32 1, !"wchar_size", i32 4}
 !12 = !{i32 7, !"PIC Level", i32 2}
 !13 = !{!"clang"}
-!14 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 3, scopeLine: 3, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !4)
+!14 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 3, scopeLine: 3, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !4, type: !26)
 !24 = !DILocation(line: 7, column: 3, scope: !14)
+!25 = !{null}
+!26 = !DISubroutineType(types: !25)
diff --git a/llvm/test/CodeGen/AArch64/sdag-no-typesize-warnings-regandsizes.ll b/llvm/test/CodeGen/AArch64/sdag-no-typesize-warnings-regandsizes.ll
index 4fb816172b19d..e3ef90db8cde3 100644
--- a/llvm/test/CodeGen/AArch64/sdag-no-typesize-warnings-regandsizes.ll
+++ b/llvm/test/CodeGen/AArch64/sdag-no-typesize-warnings-regandsizes.ll
@@ -23,5 +23,7 @@ declare void @llvm.dbg.value(metadata, metadata, metadata)
 !1 = !DIFile(filename: "file.c", directory: "/")
 !2 = !{i32 2, !"Debug Info Version", i32 3}
 !3 = !DILocalVariable(scope: !4)
-!4 = distinct !DISubprogram(unit: !0)
+!4 = distinct !DISubprogram(unit: !0, type: !7)
 !5 = !DILocation(scope: !4)
+!6 = !{null}
+!7 = !DISubroutineType(types: !6)
diff --git a/llvm/test/CodeGen/AArch64/selectiondag-order.ll b/llvm/test/CodeGen/AArch64/selectiondag-order.ll
index fb40653723fec..46a7ae6521e45 100644
--- a/llvm/test/CodeGen/AArch64/selectiondag-order.ll
+++ b/llvm/test/CodeGen/AArch64/selectiondag-order.ll
@@ -90,7 +90,9 @@ declare void @llvm.dbg.declare(metadata, metadata, metadata)
 !2 = !DIFile(filename: "test.ll", directory: ".")
 !3 = !{i32 2, !"Dwarf Version", i32 4}
 !4 = !{i32 2, !"Debug Info Version", i32 3}
-!5 = distinct !DISubprogram(name: "simulateWithDebugIntrinsic", scope: !2, file: !2, line: 64, isLocal: false, isDefinition: true, scopeLine: 65, unit: !1)
+!5 = distinct !DISubprogram(name: "simulateWithDebugIntrinsic", scope: !2, file: !2, line: 64, isLocal: false, isDefinition: true, scopeLine: 65, unit: !1, type: !10)
 !6 = !DILocalVariable(name: "randv", scope: !5, file: !2, line: 69)
 !7 = !DIExpression()
 !8 = !DILocation(line: 132, column: 2, scope: !5)
+!9 = !{null}
+!10 = !DISubroutineType(types: !9)
diff --git a/llvm/test/CodeGen/AMDGPU/simplify-libcalls2.ll b/llvm/test/CodeGen/AMDGPU/simplify-libcalls2.ll
index 692a73a9bc593..9edefe5ff53ff 100644
--- a/llvm/test/CodeGen/AMDGPU/simplify-libcalls2.ll
+++ b/llvm/test/CodeGen/AMDGPU/simplify-libcalls2.ll
@@ -20,5 +20,7 @@ declare void @llvm.dbg.value(metadata, metadata, metadata)
 
 !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !DIFile(filename: "1", directory: "1"))
 !1 = !{i32 2, !"Debug Info Version", i32 3}
-!2 = distinct !DISubprogram(unit: !0)
+!2 = distinct !DISubprogram(unit: !0, type: !5)
 !3 = !DILocation(line: 1, column: 1, scope: !2)
+!4 = !{null}
+!5 = !DISubroutineType(types: !4)
diff --git a/llvm/test/CodeGen/ARM/2009-10-16-Scope.ll b/llvm/test/CodeGen/ARM/2009-10-16-Scope.ll
index c01f3bf352b18..90a72db645fa5 100644
--- a/llvm/test/CodeGen/ARM/2009-10-16-Scope.ll
+++ b/llvm/test/CodeGen/ARM/2009-10-16-Scope.ll
@@ -25,7 +25,7 @@ declare i32 @foo(i32) ssp
 !llvm.dbg.cu = !{!0}
 !0 = !DILocation(line: 5, column: 2, scope: !1)
 !1 = distinct !DILexicalBlock(line: 1, column: 1, file: null, scope: !2)
-!2 = distinct !DISubprogram(name: "bar", linkageName: "bar", line: 4, isLocal: false, isDefinition: true, virtualIndex: 6, isOptimized: false, unit: !3, scope: !3)
+!2 = distinct !DISubprogram(name: "bar", linkageName: "bar", line: 4, isLocal: false, isDefinition: true, virtualIndex: 6, isOptimized: false, unit: !3, scope: !3, type: !11)
 !3 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang 1.1", isOptimized: true, emissionKind: FullDebug, file: !8, retainedTypes: !9)
 !4 = !DILocalVariable(name: "count_", line: 5, scope: !5, file: !3, type: !6)
 !5 = distinct !DILexicalBlock(line: 1, column: 1, file: null, scope: !1)
@@ -33,3 +33,5 @@ declare i32 @foo(i32) ssp
 !7 = !DILocation(line: 6, column: 1, scope: !2)
 !8 = !DIFile(filename: "genmodes.i", directory: "/Users/yash/Downloads")
 !9 = !{i32 0}
+!10 = !{null}
+!11 = !DISubroutineType(types: !10)
diff --git a/llvm/test/CodeGen/ARM/analyze-branch-bkpt.ll b/llvm/test/CodeGen/ARM/analyze-branch-bkpt.ll
index cba89fe998700..d6a2f58589c32 100644
--- a/llvm/test/CodeGen/ARM/analyze-branch-bkpt.ll
+++ b/llvm/test/CodeGen/ARM/analyze-branch-bkpt.ll
@@ -50,12 +50,14 @@ attributes #1 = { nounwind }
 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug)
 !1 = !DIFile(filename: "a", directory: "")
 !2 = !{i32 2, !"Debug Info Version", i32 3}
-!3 = distinct !DISubprogram(scope: null, isLocal: false, isDefinition: true, isOptimized: false, unit: !0)
+!3 = distinct !DISubprogram(scope: null, isLocal: false, isDefinition: true, isOptimized: false, unit: !0, type: !13)
 !4 = !DILocation(line: 0, scope: !5, inlinedAt: !6)
-!5 = distinct !DISubprogram(scope: null, isLocal: false, isDefinition: true, isOptimized: false, unit: !0)
+!5 = distinct !DISubprogram(scope: null, isLocal: false, isDefinition: true, isOptimized: false, unit: !0, type: !13)
 !6 = !DILocation(line: 0, scope: !3)
 !7 = !DILocalVariable(scope: !8)
-!8 = distinct !DISubprogram(scope: null, isLocal: false, isDefinition: true, isOptimized: false, unit: !0)
+!8 = distinct !DISubprogram(scope: null, isLocal: false, isDefinition: true, isOptimized: false, unit: !0, type: !13)
 !9 = !DILocation(line: 0, scope: !8, inlinedAt: !6)
 !10 = !DILocation(line: 0, scope: !11, inlinedAt: !6)
 !11 = !DILexicalBlock(scope: !8)
+!12 = !{null}
+!13 = !DISubroutineType(types: !12)
diff --git a/llvm/test/CodeGen/Generic/dbg_value.ll b/llvm/test/CodeGen/Generic/dbg_value.ll
index a143801bf7eba..54870d51bb2e3 100644
--- a/llvm/test/CodeGen/Generic/dbg_value.ll
+++ b/llvm/test/CodeGen/Generic/dbg_value.ll
@@ -12,4 +12,6 @@ declare void @llvm.dbg.value(metadata, i64, metadata, metadata) nounwind readnon
 
 ; !0 should conform to the format of DIVariable.
 !0 = !DILocalVariable(name: "a", arg: 1, scope: !1)
-!1 = distinct !DISubprogram()
+!1 = distinct !DISubprogram(type: !3)
+!2 = !{null}
+!3 = !DISubroutineType(types: !2)
diff --git a/llvm/test/CodeGen/MIR/X86/fixed-stack-di.mir b/llvm/test/CodeGen/MIR/X86/fixed-stack-di.mir
index fca249320bc82..6351b9bded8c8 100644
--- a/llvm/test/CodeGen/MIR/X86/fixed-stack-di.mir
+++ b/llvm/test/CodeGen/MIR/X86/fixed-stack-di.mir
@@ -23,8 +23,10 @@
   !1 = !DIFile(filename: "file.cpp", directory: "/dir")
   !2 = !{i32 2, !"Debug Info Version", i32 3}
   !3 = !DILocalVariable(name: "dstRect", scope: !4)
-  !4 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !0, file: !1, line: 42, unit: !0)
+  !4 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !0, file: !1, line: 42, unit: !0, type: !7)
   !5 = !DILocation(line: 42, column: 85, scope: !4)
+  !6 = !{null}
+  !7 = !DISubroutineType(types: !6)
 
 ...
 ---
diff --git a/llvm/test/CodeGen/MIR/X86/invalid-metadata-node-type.mir b/llvm/test/CodeGen/MIR/X86/invalid-metadata-node-type.mir
index 1a83f891d1fa4..ec98834857f1f 100644
--- a/llvm/test/CodeGen/MIR/X86/invalid-metadata-node-type.mir
+++ b/llvm/test/CodeGen/MIR/X86/invalid-metadata-node-type.mir
@@ -27,10 +27,12 @@
   !2 = !{}
   !3 = !{i32 1, !"Debug Info Version", i32 3}
   !4 = !DILocalVariable(name: "x", scope: !5, file: !1, line: 16, type: !6)
-  !5 = distinct !DISubprogram(scope: null, isLocal: false, isDefinition: true, isOptimized: false, unit: !0)
+  !5 = distinct !DISubprogram(scope: null, isLocal: false, isDefinition: true, isOptimized: false, unit: !0, type: !10)
   !6 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char)
   !7 = !DIExpression()
   !8 = !DILocation(line: 0, scope: !5)
+  !9 = !{null}
+  !10 = !DISubroutineType(types: !9)
 ...
 ---
 name:            foo
diff --git a/llvm/test/CodeGen/RISCV/rvv/get-vlen-debugloc.mir b/llvm/test/CodeGen/RISCV/rvv/get-vlen-debugloc.mir
index c493a6ca180aa..1d9b8b2d429be 100644
--- a/llvm/test/CodeGen/RISCV/rvv/get-vlen-debugloc.mir
+++ b/llvm/test/CodeGen/RISCV/rvv/get-vlen-debugloc.mir
@@ -11,9 +11,11 @@
     ret void, !dbg !2
   }
 
-  !0 = distinct !DISubprogram(name: "foo", line: 3, scopeLine: 3)
+  !0 = distinct !DISubprogram(name: "foo", line: 3, scopeLine: 3, type: !4)
   !1 = !DILocation(line: 4, column: 14, scope: !0)
   !2 = !DILocation(line: 5, column: 3, scope: !0)
+  !3 = !{null}
+  !4 = !DISubroutineType(types: !3)
 
 ...
 ---
diff --git a/llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll b/llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll
index 51dcf2fc7ec62..bb80e4886da5e 100644
--- a/llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll
+++ b/llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll
@@ -302,9 +302,11 @@ attributes #3 = { allocsize(0) }
 !0 = !{i32 2, !"Debug Info Version", i32 3}
 !1 = !DIFile(filename: "lower-em-sjlj.c", directory: "test")
 !2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1)
-!3 = distinct !DISubprogram(name: "setjmp_debug_info", unit:!2, file: !1, line: 1)
+!3 = distinct !DISubprogram(name: "setjmp_debug_info", unit:!2, file: !1, line: 1, type: !10)
 !4 = !DILocation(line:2, scope: !3)
 !5 = !DILocation(line:3, scope: !3)
 !6 = !DILocation(line:4, scope: !3)
 !7 = !DILocation(line:5, scope: !3)
 !8 = !DILocation(line:6, scope: !3)
+!9 = !{null}
+!10 = !DISubroutineType(types: !9)
diff --git a/llvm/test/CodeGen/X86/2009-10-16-Scope.ll b/llvm/test/CodeGen/X86/2009-10-16-Scope.ll
index bb568713d5c6a..1e3356fcc08b3 100644
--- a/llvm/test/CodeGen/X86/2009-10-16-Scope.ll
+++ b/llvm/test/CodeGen/X86/2009-10-16-Scope.ll
@@ -25,7 +25,7 @@ declare i32 @foo(i32) ssp
 !llvm.dbg.cu = !{!3}
 !0 = !DILocation(line: 5, column: 2, scope: !1)
 !1 = distinct !DILexicalBlock(line: 1, column: 1, file: null, scope: !2)
-!2 = distinct !DISubprogram(name: "bar", linkageName: "bar", line: 4, isLocal: false, isDefinition: true, virtualIndex: 6, isOptimized: false, unit: !3, scope: !3)
+!2 = distinct !DISubprogram(name: "bar", linkageName: "bar", line: 4, isLocal: false, isDefinition: true, virtualIndex: 6, isOptimized: false, unit: !3, scope: !3, type: !11)
 !3 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang 1.1", isOptimized: true, emissionKind: FullDebug, file: !8, retainedTypes: !9)
 !4 = !DILocalVariable(name: "count_", line: 5, scope: !5, file: !3, type: !6)
 !5 = distinct !DILexicalBlock(line: 1, column: 1, file: null, scope: !1)
@@ -33,3 +33,5 @@ declare i32 @foo(i32) ssp
 !7 = !DILocation(line: 6, column: 1, scope: !2)
 !8 = !DIFile(filename: "genmodes.i", directory: "/Users/yash/Downloads")
 !9 = !{i32 0}
+!10 = !{null}
+!11 = !DISubroutineType(types: !10)
diff --git a/llvm/test/CodeGen/X86/AMX/amx-ldtilecfg-insert.ll b/llvm/test/CodeGen/X86/AMX/amx-ldtilecfg-insert.ll
index 8a8e7a3b4df2c..972e507793799 100644
--- a/llvm/test/CodeGen/X86/AMX/amx-ldtilecfg-insert.ll
+++ b/llvm/test/CodeGen/X86/AMX/amx-ldtilecfg-insert.ll
@@ -366,5 +366,7 @@ declare void @llvm.x86.tilestored64.internal(i16, i16, ptr, i64, x86_amx)
 
 !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !DIFile(filename: "1", directory: "1"))
 !1 = !{i32 2, !"Debug Info Version", i32 3}
-!2 = distinct !DISubprogram(unit: !0)
+!2 = distinct !DISubprogram(unit: !0, type: !5)
 !3 = !DILocation(line: 1, column: 1, scope: !2)
+!4 = !{null}
+!5 = !DISubroutineType(types: !4)
diff --git a/llvm/test/CodeGen/X86/GlobalISel/regbankselect-dbg-value-physreg-crash.mir b/llvm/test/CodeGen/X86/GlobalISel/regbankselect-dbg-value-physreg-crash.mir
index 79523b904ee9a..085fa2c55b645 100644
--- a/llvm/test/CodeGen/X86/GlobalISel/regbankselect-dbg-value-physreg-crash.mir
+++ b/llvm/test/CodeGen/X86/GlobalISel/regbankselect-dbg-value-physreg-crash.mir
@@ -11,8 +11,10 @@
     ret void
   }
 
-  !0 = distinct !DISubprogram(name: "foo")
+  !0 = distinct !DISubprogram(name: "foo", type: !3)
   !1 = !DILocation(line: 1, column: 1, scope: !0)
+  !2 = !{null}
+  !3 = !DISubroutineType(types: !2)
 ...
 
 ---
diff --git a/llvm/test/CodeGen/X86/StackColoring-dbg.ll b/llvm/test/CodeGen/X86/StackColoring-dbg.ll
index ccb1c3fdb27fe..c1b29a773adfb 100644
--- a/llvm/test/CodeGen/X86/StackColoring-dbg.ll
+++ b/llvm/test/CodeGen/X86/StackColoring-dbg.ll
@@ -30,6 +30,8 @@ declare void @llvm.lifetime.end.p0(i64, ptr nocapture) nounwind
 !0 = distinct !DICompileUnit(language: DW_LANG_C89, producer: "clang", isOptimized: true, emissionKind: FullDebug, file: !1, enums: !{}, retainedTypes: !{})
 !1 = !DIFile(filename: "t.c", directory: "")
 !16 = !DIBasicType(tag: DW_TAG_base_type, name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char)
-!2 = distinct !DISubprogram(unit: !0)
+!2 = distinct !DISubprogram(unit: !0, type: !25)
 !22 = !DILocalVariable(name: "x", line: 16, scope: !2, file: !1, type: !16)
 !23 = !{i32 1, !"Debug Info Version", i32 3}
+!24 = !{null}
+!25 = !DISubroutineType(types: !24)
diff --git a/llvm/test/CodeGen/X86/addrsig.ll b/llvm/test/CodeGen/X86/addrsig.ll
index e306681b00a16..0e30fdc68e149 100644
--- a/llvm/test/CodeGen/X86/addrsig.ll
+++ b/llvm/test/CodeGen/X86/addrsig.ll
@@ -86,8 +86,10 @@ declare void @llvm.dbg.value(metadata, metadata, metadata)
 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug)
 !1 = !DIFile(filename: "a", directory: "")
 !2 = !{i32 2, !"Debug Info Version", i32 3}
-!3 = distinct !DISubprogram(scope: null, isLocal: false, isDefinition: true, isOptimized: false, unit: !0)
+!3 = distinct !DISubprogram(scope: null, isLocal: false, isDefinition: true, isOptimized: false, unit: !0, type: !9)
 !4 = !DILocation(line: 0, scope: !3)
 !5 = !DILocalVariable(scope: !6)
-!6 = distinct !DISubprogram(scope: null, isLocal: false, isDefinition: true, isOptimized: false, unit: !0)
+!6 = distinct !DISubprogram(scope: null, isLocal: false, isDefinition: true, isOptimized: false, unit: !0, type: !9)
 !7 = !DILocation(line: 0, scope: !6, inlinedAt: !4)
+!8 = !{null}
+!9 = !DISubroutineType(types: !8)
diff --git a/llvm/test/CodeGen/X86/dbg-changes-codegen.ll b/llvm/test/CodeGen/X86/dbg-changes-codegen.ll
index c688895335181..eb53edcb48954 100644
--- a/llvm/test/CodeGen/X86/dbg-changes-codegen.ll
+++ b/llvm/test/CodeGen/X86/dbg-changes-codegen.ll
@@ -72,10 +72,12 @@ attributes #0 = { nounwind readonly uwtable "less-precise-fpmad"="false" "frame-
 attributes #1 = { nounwind uwtable "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "use-soft-float"="false" }
 attributes #2 = { nounwind readnone }
 
-!1 = distinct !DISubprogram()
+!1 = distinct !DISubprogram(type: !67)
 
 !17 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: null)
 !45 = !DIDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, baseType: null)
 !62 = !DILocalVariable(name: "arg", line: 4, arg: 2, scope: !1, type: !17)
 !64 = !{ptr undef}
 !65 = !DILocalVariable(name: "this", line: 13, arg: 1, flags: DIFlagArtificial | DIFlagObjectPointer, scope: !1, type: !45)
+!66 = !{null}
+!67 = !DISubroutineType(types: !66)
diff --git a/llvm/test/CodeGen/X86/frame-lowering-debug-intrinsic-2.ll b/llvm/test/CodeGen/X86/frame-lowering-debug-intrinsic-2.ll
index b3761ff7d7edc..12d635aefe87b 100644
--- a/llvm/test/CodeGen/X86/frame-lowering-debug-intrinsic-2.ll
+++ b/llvm/test/CodeGen/X86/frame-lowering-debug-intrinsic-2.ll
@@ -68,7 +68,7 @@ declare void @llvm.dbg.value(metadata, i64, metadata, metadata)
 !11 = !DIBasicType(name: "long int", size: 64, encoding: DW_ATE_signed)
 !15 = !{i32 2, !"Dwarf Version", i32 4}
 !16 = !{i32 2, !"Debug Info Version", i32 3}
-!18 = distinct !DISubprogram(name: "test", scope: !2, file: !2, line: 5, unit: !1)
+!18 = distinct !DISubprogram(name: "test", scope: !2, file: !2, line: 5, unit: !1, type: !39)
 !22 = !DILocalVariable(name: "i", scope: !18, file: !2, line: 6, type: !11)
 !23 = !DILocalVariable(name: "j", scope: !18, file: !2, line: 7, type: !11)
 !33 = !DIExpression()
@@ -76,3 +76,5 @@ declare void @llvm.dbg.value(metadata, i64, metadata, metadata)
 !35 = !DILocation(line: 6, column: 8, scope: !18)
 !36 = !DILocation(line: 9, column: 3, scope: !18)
 !37 = !DILocation(line: 10, column: 10, scope: !18)
+!38 = !{null}
+!39 = !DISubroutineType(types: !38)
diff --git a/llvm/test/CodeGen/X86/frame-lowering-debug-intrinsic.ll b/llvm/test/CodeGen/X86/frame-lowering-debug-intrinsic.ll
index 053dd3dd672df..a8ad288d40dbd 100644
--- a/llvm/test/CodeGen/X86/frame-lowering-debug-intrinsic.ll
+++ b/llvm/test/CodeGen/X86/frame-lowering-debug-intrinsic.ll
@@ -64,10 +64,12 @@ declare void @llvm.dbg.declare(metadata, metadata, metadata)
 !1 = !DIFile(filename: "test.c", directory: "/")
 !2 = !{i32 2, !"Dwarf Version", i32 4}
 !3 = !{i32 2, !"Debug Info Version", i32 3}
-!4 = distinct !DISubprogram(name: "withDebug", unit: !0)
+!4 = distinct !DISubprogram(name: "withDebug", unit: !0, type: !12)
 !5 = !DILocalVariable(name: "w", scope: !4)
 !6 = !DIExpression()
 !7 = !DILocation(line: 210, column: 12, scope: !4)
-!8 = distinct !DISubprogram(name: "withDebug", unit: !0)
+!8 = distinct !DISubprogram(name: "withDebug", unit: !0, type: !12)
 !9 = !DILocalVariable(name: "w", scope: !8)
 !10 = !DILocation(line: 210, column: 12, scope: !8)
+!11 = !{null}
+!12 = !DISubroutineType(types: !11)
diff --git a/llvm/test/CodeGen/X86/lrshrink.ll b/llvm/test/CodeGen/X86/lrshrink.ll
index b72a5a413c573..67bebf239e4c8 100644
--- a/llvm/test/CodeGen/X86/lrshrink.ll
+++ b/llvm/test/CodeGen/X86/lrshrink.ll
@@ -83,6 +83,8 @@ declare void @llvm.dbg.value(metadata, i64, metadata, metadata)
 !1 = !{i32 2, !"Dwarf Version", i32 4}
 !2 = !{i32 2, !"Debug Info Version", i32 3}
 !3 = !DIFile(filename: "a.c", directory: "./")
-!4 = distinct !DISubprogram(name: "test", scope: !3, unit: !0)
+!4 = distinct !DISubprogram(name: "test", scope: !3, unit: !0, type: !8)
 !5 = !DILocalVariable(name: "x", scope: !4)
 !6 = !DILocation(line: 4, scope: !4)
+!7 = !{null}
+!8 = !DISubroutineType(types: !7)
diff --git a/llvm/test/CodeGen/X86/machine-trace-metrics-crash.ll b/llvm/test/CodeGen/X86/machine-trace-metrics-crash.ll
index 09d1dd9ccef95..f0457fa3eed8f 100644
--- a/llvm/test/CodeGen/X86/machine-trace-metrics-crash.ll
+++ b/llvm/test/CodeGen/X86/machine-trace-metrics-crash.ll
@@ -92,7 +92,9 @@ declare void @llvm.dbg.value(metadata, i64, metadata, metadata)
 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
 !1 = !DIFile(filename: "24199.cpp", directory: "/bin")
 !2 = !{i32 2, !"Debug Info Version", i32 3}
-!3 = distinct !DISubprogram(linkageName: "foo", file: !1, line: 18, isLocal: false, isDefinition: true, scopeLine: 18, unit: !0)
+!3 = distinct !DISubprogram(linkageName: "foo", file: !1, line: 18, isLocal: false, isDefinition: true, scopeLine: 18, unit: !0, type: !8)
 !4 = !DIExpression()
 !5 = !DILocalVariable(name: "this", arg: 1, scope: !3, flags: DIFlagArtificial | DIFlagObjectPointer)
 !6 = !DILocation(line: 0, scope: !3)
+!7 = !{null}
+!8 = !DISubroutineType(types: !7)
diff --git a/llvm/test/CodeGen/X86/opt_phis.mir b/llvm/test/CodeGen/X86/opt_phis.mir
index db4fa9efeb2d8..3be406d1294aa 100644
--- a/llvm/test/CodeGen/X86/opt_phis.mir
+++ b/llvm/test/CodeGen/X86/opt_phis.mir
@@ -14,9 +14,11 @@
   !2 = !{i32 2, !"Dwarf Version", i32 4}
   !3 = !{i32 2, !"Debug Info Version", i32 3}
   !4 = !{!"My Compiler"}
-  !5 = distinct !DISubprogram(name: "test")
+  !5 = distinct !DISubprogram(name: "test", type: !9)
   !6 = !DILocation(line: 7, column: 11, scope: !5)
   !7 = !DILocalVariable(name: "l", scope: !5)
+  !8 = !{null}
+  !9 = !DISubroutineType(types: !8)
 
 ...
 ---
diff --git a/llvm/test/CodeGen/X86/pr149841.ll b/llvm/test/CodeGen/X86/pr149841.ll
index c17a6172dee0c..6402cff7d97d8 100644
--- a/llvm/test/CodeGen/X86/pr149841.ll
+++ b/llvm/test/CodeGen/X86/pr149841.ll
@@ -29,6 +29,7 @@ bb:
 !1 = !DIFile(filename: "x.c", directory: "/proc/self/cwd")
 !2 = !{i32 2, !"Debug Info Version", i32 3}
 !3 = !DILocalVariable(name: "x", arg: 1, scope: !4, file: !1)
-!4 = distinct !DISubprogram(name: "x", scope: null, file: !1, spFlags: DISPFlagDefinition, unit: !0)
+!4 = distinct !DISubprogram(name: "x", scope: null, file: !1, spFlags: DISPFlagDefinition, unit: !0, type: !7)
 !5 = !DILocation(line: 0, scope: !4)
-
+!6 = !{null}
+!7 = !DISubroutineType(types: !6)
diff --git a/llvm/test/CodeGen/X86/pr57673.mir b/llvm/test/CodeGen/X86/pr57673.mir
index c183affb9c039..052af75987d24 100644
--- a/llvm/test/CodeGen/X86/pr57673.mir
+++ b/llvm/test/CodeGen/X86/pr57673.mir
@@ -16,9 +16,11 @@
   }
 
   !0 = !DIFile(filename: "a", directory: "/proc/self/cwd")
-  !1 = distinct !DISubprogram(name: "c", scope: null, file: !0, line: 3)
+  !1 = distinct !DISubprogram(name: "c", scope: null, file: !0, line: 3, type: !5)
   !2 = !DILocalVariable(name: "r", scope: !1, file: !0, line: 4)
   !3 = !DILocation(line: 5, scope: !1)
+  !4 = !{null}
+  !5 = !DISubroutineType(types: !4)
 ...
 ---
 name: foo
diff --git a/llvm/test/CodeGen/X86/selectiondag-dbgvalue-null-crash.ll b/llvm/test/CodeGen/X86/selectiondag-dbgvalue-null-crash.ll
index 69b4b7adbc07c..1826f4e683630 100644
--- a/llvm/test/CodeGen/X86/selectiondag-dbgvalue-null-crash.ll
+++ b/llvm/test/CodeGen/X86/selectiondag-dbgvalue-null-crash.ll
@@ -30,8 +30,10 @@ entry:
 !1 = !DIFile(filename: "test_selectiondag.cpp", directory: "/home/AnonTokyo/documents/llvm-project/temp")
 !2 = !{i32 2, !"Debug Info Version", i32 3}
 !3 = !{i32 2, !"Dwarf Version", i32 4}
-!4 = distinct !DISubprogram(name: "test_empty_struct_debug", scope: !1, file: !1, line: 1, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !0)
+!4 = distinct !DISubprogram(name: "test_empty_struct_debug", scope: !1, file: !1, line: 1, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !0, type: !10)
 !5 = !DILocalVariable(name: "v1", scope: !4, file: !1, line: 2)
 !6 = !DILocation(line: 2, column: 1, scope: !4)
 !7 = !DILocalVariable(name: "v2", scope: !4, file: !1, line: 3)
 !8 = !DILocation(line: 3, column: 1, scope: !4)
+!9 = !{null}
+!10 = !DISubroutineType(types: !9)
diff --git a/llvm/test/CodeGen/X86/selectiondag-order.ll b/llvm/test/CodeGen/X86/selectiondag-order.ll
index 163e2cb90b2fe..c65659f5dc095 100644
--- a/llvm/test/CodeGen/X86/selectiondag-order.ll
+++ b/llvm/test/CodeGen/X86/selectiondag-order.ll
@@ -91,7 +91,9 @@ declare void @llvm.dbg.declare(metadata, metadata, metadata)
 !2 = !DIFile(filename: "test.ll", directory: ".")
 !3 = !{i32 2, !"Dwarf Version", i32 4}
 !4 = !{i32 2, !"Debug Info Version", i32 3}
-!5 = distinct !DISubprogram(name: "simulateWithDebugIntrinsic", scope: !2, file: !2, line: 64, isLocal: false, isDefinition: true, scopeLine: 65, unit: !1)
+!5 = distinct !DISubprogram(name: "simulateWithDebugIntrinsic", scope: !2, file: !2, line: 64, isLocal: false, isDefinition: true, scopeLine: 65, unit: !1, type: !10)
 !6 = !DILocalVariable(name: "randv", scope: !5, file: !2, line: 69)
 !7 = !DIExpression()
 !8 = !DILocation(line: 132, column: 2, scope: !5)
+!9 = !{null}
+!10 = !DISubroutineType(types: !9)
diff --git a/llvm/test/DebugInfo/AArch64/abstract-sp-unit.ll b/llvm/test/DebugInfo/AArch64/abstract-sp-unit.ll
index 559f20122cc47..977b588924f76 100644
--- a/llvm/test/DebugInfo/AArch64/abstract-sp-unit.ll
+++ b/llvm/test/DebugInfo/AArch64/abstract-sp-unit.ll
@@ -28,14 +28,14 @@ define void @a() !dbg !10 {
 !11 = !DISubroutineType(types: !12)
 !12 = !{}
 !13 = !DILocation(scope: !14, inlinedAt: !15)
-!14 = distinct !DISubprogram(unit: !6)
+!14 = distinct !DISubprogram(unit: !6, type: !11)
 !15 = !DILocation(scope: !16, inlinedAt: !25)
 !16 = distinct !DISubprogram(type: !11, unit: !6, declaration: !17)
 !17 = !DISubprogram(scope: !5, type: !11, spFlags: DISPFlagOptimized, templateParams: !18)
 !18 = !{!19}
 !19 = !DITemplateTypeParameter(type: !20)
 !20 = !DICompositeType(tag: DW_TAG_class_type, scope: !21)
-!21 = distinct !DISubprogram(unit: !6, retainedNodes: !22)
+!21 = distinct !DISubprogram(unit: !6, retainedNodes: !22, type: !11)
 !22 = !{!23}
 !23 = !DILocalVariable(scope: !21, type: !24)
 !24 = !DIBasicType()
diff --git a/llvm/test/DebugInfo/AArch64/merge-locations-legalizer.mir b/llvm/test/DebugInfo/AArch64/merge-locations-legalizer.mir
index 3bdf87cea0e56..e70ec396bffc4 100644
--- a/llvm/test/DebugInfo/AArch64/merge-locations-legalizer.mir
+++ b/llvm/test/DebugInfo/AArch64/merge-locations-legalizer.mir
@@ -14,12 +14,14 @@
   }
   !3 = !DIFile(filename: "main.swift", directory: "/Volumes/Data/swift")
   !23 = distinct !DICompileUnit(language: DW_LANG_Swift, file: !3, sdk: "blah.sdk")
-  !57 = distinct !DISubprogram(name: "main", unit: !23)
+  !57 = distinct !DISubprogram(name: "main", unit: !23, type: !73)
   !64 = distinct !DILexicalBlock(scope: !57, column: 1)
   !66 = distinct !DILexicalBlock(scope: !64, column: 1)
   !68 = !DILocation(line: 12, scope: !66)
   !70 = distinct !DILexicalBlock(scope: !66, column: 1)
   !71 = !DILocation(line: 13, scope: !70)
+  !72 = !{null}
+  !73 = !DISubroutineType(types: !72)
 name:            main
 body:             |
   bb.0:
diff --git a/llvm/test/DebugInfo/Generic/split-dwarf-local-import2.ll b/llvm/test/DebugInfo/Generic/split-dwarf-local-import2.ll
index 0057f675f9b31..2ca737125480c 100644
--- a/llvm/test/DebugInfo/Generic/split-dwarf-local-import2.ll
+++ b/llvm/test/DebugInfo/Generic/split-dwarf-local-import2.ll
@@ -26,7 +26,7 @@ lbl:
 !3 = !DIFile(filename: "b.cc", directory: "")
 !4 = !{!5}
 !5 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !6, entity: !7)
-!6 = !DISubprogram(scope: null, spFlags: DISPFlagOptimized, retainedNodes: !4)
+!6 = !DISubprogram(scope: null, spFlags: DISPFlagOptimized, retainedNodes: !4, type: !8)
 !7 = !DINamespace(scope: !2)
 !8 = !DISubroutineType(types: !9)
 !9 = !{}
@@ -35,10 +35,10 @@ lbl:
 !12 = !{i32 2, !"Debug Info Version", i32 3}
 !13 = distinct !DISubprogram(scope: null, type: !8, spFlags: DISPFlagDefinition, unit: !0)
 !16 = !DILocation(line: 0, scope: !17, inlinedAt: !18)
-!17 = distinct !DISubprogram(scope: null, unit: !10)
+!17 = distinct !DISubprogram(scope: null, unit: !10, type: !8)
 !18 = !DILocation(line: 0, scope: !21)
 !21 = !DILexicalBlockFile(scope: !13, discriminator: 0)
 !22 = distinct !DISubprogram(scope: null, type: !8, spFlags: DISPFlagDefinition, unit: !0)
 !23 = !DILocation(line: 0, scope: !24, inlinedAt: !25)
-!24 = distinct !DISubprogram(scope: null, unit: !2)
+!24 = distinct !DISubprogram(scope: null, unit: !2, type: !8)
 !25 = !DILocation(line: 0, scope: !22)
diff --git a/llvm/test/DebugInfo/MIR/X86/regcoalescing-clears-dead-dbgvals.mir b/llvm/test/DebugInfo/MIR/X86/regcoalescing-clears-dead-dbgvals.mir
index 4b5f19d66845a..6c6e832c2a8c5 100644
--- a/llvm/test/DebugInfo/MIR/X86/regcoalescing-clears-dead-dbgvals.mir
+++ b/llvm/test/DebugInfo/MIR/X86/regcoalescing-clears-dead-dbgvals.mir
@@ -53,8 +53,10 @@
   !1 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !2, producer: "beards", isOptimized: true, runtimeVersion: 4, emissionKind: FullDebug)
   !2 = !DIFile(filename: "bees.cpp", directory: "")
   !3 = !DILocalVariable(name: "bees", scope: !4)
-  !4 = distinct !DISubprogram(name: "nope", scope: !1, file: !2, line: 1, spFlags: DISPFlagDefinition, unit: !1)
+  !4 = distinct !DISubprogram(name: "nope", scope: !1, file: !2, line: 1, spFlags: DISPFlagDefinition, unit: !1, type: !7)
   !5 = !DILocation(line: 0, scope: !4)
+  !6 = !{null}
+  !7 = !DISubroutineType(types: !6)
 
 ...
 ---
diff --git a/llvm/test/DebugInfo/X86/empty-struct-no-crash.ll b/llvm/test/DebugInfo/X86/empty-struct-no-crash.ll
index 0fe390e247ad7..526d1d2e4175f 100644
--- a/llvm/test/DebugInfo/X86/empty-struct-no-crash.ll
+++ b/llvm/test/DebugInfo/X86/empty-struct-no-crash.ll
@@ -1,5 +1,5 @@
 ; RUN: llc -mtriple=x86_64-apple-darwin -o /dev/null %s
-; Verify we don't crash on DISubprogram without a type.
+; Verify we don't crash on a DISubprogram with an empty struct type.
 
 target triple = "x86_64-apple-darwin"
 
@@ -14,4 +14,6 @@ define void @test() !dbg !4 {
 !1 = !DIFile(filename: "test.cpp", directory: "/tmp")
 !2 = !{i32 2, !"Debug Info Version", i32 3}
 !3 = !{i32 2, !"Dwarf Version", i32 4}
-!4 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 1, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !0)
\ No newline at end of file
+!4 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 1, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !0, type: !6)
+!5 = !{null}
+!6 = !DISubroutineType(types: !5)
diff --git a/llvm/test/LTO/X86/Inputs/strip-debug-info-bar.ll b/llvm/test/LTO/X86/Inputs/strip-debug-info-bar.ll
index be4322caa77fc..24b1c7f209937 100644
--- a/llvm/test/LTO/X86/Inputs/strip-debug-info-bar.ll
+++ b/llvm/test/LTO/X86/Inputs/strip-debug-info-bar.ll
@@ -11,5 +11,6 @@ define void @bar() !dbg !3 {
 !0 = !{i32 2, !"Debug Info Version", i32 3}
 !1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2)
 !2 = !DIFile(filename: "broken", directory: "")
-!3 = distinct !DISubprogram(line: 1000, isDefinition: true)
-
+!3 = distinct !DISubprogram(line: 1000, isDefinition: true, type: !5)
+!4 = !{null}
+!5 = !DISubroutineType(types: !4)
diff --git a/llvm/test/LTO/X86/Inputs/type-mapping-bug2.ll b/llvm/test/LTO/X86/Inputs/type-mapping-bug2.ll
index e866cb712279e..f421fc1af8eac 100644
--- a/llvm/test/LTO/X86/Inputs/type-mapping-bug2.ll
+++ b/llvm/test/LTO/X86/Inputs/type-mapping-bug2.ll
@@ -13,4 +13,6 @@ define i32 @c() !dbg !6 {
 !3 = !DIFile(filename: "f2", directory: "")
 !4 = !{!5}
 !5 = !DICompositeType(tag: DW_TAG_class_type, file: !3, flags: DIFlagFwdDecl, identifier: "SHARED")
-!6 = distinct !DISubprogram(unit: !2)
+!6 = distinct !DISubprogram(unit: !2, type: !8)
+!7 = !{null}
+!8 = !DISubroutineType(types: !7)
diff --git a/llvm/test/LTO/X86/Inputs/type-mapping-bug3.ll b/llvm/test/LTO/X86/Inputs/type-mapping-bug3.ll
index 6b965ef28803a..453173691402b 100644
--- a/llvm/test/LTO/X86/Inputs/type-mapping-bug3.ll
+++ b/llvm/test/LTO/X86/Inputs/type-mapping-bug3.ll
@@ -23,4 +23,6 @@ define void @a(%"T2") !dbg !6 {
 ; This DICompositeType refers to !5 in type-mapping-bug3.ll
 !5 = !DICompositeType(tag: DW_TAG_structure_type, flags: DIFlagFwdDecl, identifier: "SHARED")
 
-!6 = distinct !DISubprogram(unit: !2)
+!6 = distinct !DISubprogram(unit: !2, type: !8)
+!7 = !{null}
+!8 = !DISubroutineType(types: !7)
diff --git a/llvm/test/LTO/X86/pr38046.ll b/llvm/test/LTO/X86/pr38046.ll
index 8f04190f0c83f..9cf945d63b878 100644
--- a/llvm/test/LTO/X86/pr38046.ll
+++ b/llvm/test/LTO/X86/pr38046.ll
@@ -30,5 +30,7 @@ declare void @llvm.dbg.value(metadata, metadata, metadata)
 !3 = !{i32 2, !"Debug Info Version", i32 3}
 !4 = !{i32 1, !"wchar_size", i32 4}
 !5 = !{i32 1, !"ThinLTO", i32 0}
-!6 = distinct !DISubprogram(unit: !0)
+!6 = distinct !DISubprogram(unit: !0, type: !9)
 !7 = !DILocalVariable(name: "get", scope: !6)
+!8 = !{null}
+!9 = !DISubroutineType(types: !8)
diff --git a/llvm/test/LTO/X86/type-mapping-bug2.ll b/llvm/test/LTO/X86/type-mapping-bug2.ll
index 8d3a3ac5d6deb..eca25c8710783 100644
--- a/llvm/test/LTO/X86/type-mapping-bug2.ll
+++ b/llvm/test/LTO/X86/type-mapping-bug2.ll
@@ -33,10 +33,11 @@ define i1 @b(ptr) {
 ; The reference to @b and T2 that will be loaded in %t0.o
 
 !7 = !DITemplateValueParameter(value: ptr @b)
-!8 = distinct !DISubprogram(unit: !2)
+!8 = distinct !DISubprogram(unit: !2, type: !15)
 
 ; This DICompositeType is uniqued against !5 in Inputs/type-mapping-bug2.ll,
 ; causing !7 and hence %T2 to be loaded into it's module
 
 !9 = !DICompositeType(tag: DW_TAG_array_type, identifier: "SHARED", scope: !8)
-
+!14 = !{null}
+!15 = !DISubroutineType(types: !14)
diff --git a/llvm/test/Linker/2009-09-03-mdnode.ll b/llvm/test/Linker/2009-09-03-mdnode.ll
index 5bd7eaf15fd98..c667c4c5864db 100644
--- a/llvm/test/Linker/2009-09-03-mdnode.ll
+++ b/llvm/test/Linker/2009-09-03-mdnode.ll
@@ -28,6 +28,8 @@ declare void @llvm.dbg.region.end(metadata) nounwind readnone
 
 !llvm.dbg.cu = !{!1}
 
-!0 = distinct !DISubprogram(name: "main", linkageName: "main", line: 2, isLocal: false, isDefinition: true, virtualIndex: 6, isOptimized: false, unit: !1, scope: !1)
+!0 = distinct !DISubprogram(name: "main", linkageName: "main", line: 2, isLocal: false, isDefinition: true, virtualIndex: 6, isOptimized: false, unit: !1, scope: !1, type: !4)
 !1 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "ellcc 0.1.0", isOptimized: true, emissionKind: FullDebug, file: !2)
 !2 = !DIFile(filename: "a.c", directory: "/home/rich/ellcc/test/source")
+!3 = !{null}
+!4 = !DISubroutineType(types: !3)
diff --git a/llvm/test/Linker/2009-09-03-mdnode2.ll b/llvm/test/Linker/2009-09-03-mdnode2.ll
index 1abed16885f01..59c0850dc402e 100644
--- a/llvm/test/Linker/2009-09-03-mdnode2.ll
+++ b/llvm/test/Linker/2009-09-03-mdnode2.ll
@@ -23,6 +23,8 @@ declare void @llvm.dbg.region.end(metadata) nounwind readnone
 
 !llvm.dbg.cu = !{!1}
 
-!0 = distinct !DISubprogram(name: "f", linkageName: "f", line: 1, isLocal: false, isDefinition: true, virtualIndex: 6, isOptimized: false, unit: !1, scope: !1)
+!0 = distinct !DISubprogram(name: "f", linkageName: "f", line: 1, isLocal: false, isDefinition: true, virtualIndex: 6, isOptimized: false, unit: !1, scope: !1, type: !4)
 !1 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "ellcc 0.1.0", isOptimized: true, emissionKind: FullDebug, file: !2)
 !2 = !DIFile(filename: "b.c", directory: "/home/rich/ellcc/test/source")
+!3 = !{null}
+!4 = !DISubroutineType(types: !3)
diff --git a/llvm/test/Linker/odr.ll b/llvm/test/Linker/odr.ll
index 2d919e44186a5..d0c0b713a09f7 100644
--- a/llvm/test/Linker/odr.ll
+++ b/llvm/test/Linker/odr.ll
@@ -16,7 +16,9 @@ source_filename = "test/Linker/odr.ll"
 !3 = !DIFile(filename: "a", directory: "")
 !4 = !{!5}
 !5 = distinct !DICompositeType(tag: DW_TAG_class_type, scope: !6, file: !3, identifier: "zed")
-!6 = distinct !DISubprogram(name: "b", scope: null, isLocal: false, isDefinition: true, isOptimized: false, unit: !2)
+!6 = distinct !DISubprogram(name: "b", scope: null, isLocal: false, isDefinition: true, isOptimized: false, unit: !2, type: !11)
 !7 = !{!0}
 !8 = !{i32 2, !"Debug Info Version", i32 3}
 !9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!10 = !{null}
+!11 = !DISubroutineType(types: !10)
diff --git a/llvm/test/Other/dropped-var-stats.ll b/llvm/test/Other/dropped-var-stats.ll
index 03bad690efca0..79151f367aa5d 100644
--- a/llvm/test/Other/dropped-var-stats.ll
+++ b/llvm/test/Other/dropped-var-stats.ll
@@ -13,13 +13,15 @@ define noundef range(i32 -2147483646, -2147483648) i32 @_Z3bari(i32 noundef %y)
 !1 = !DIFile(filename: "/tmp/dropped.cpp", directory: "/Users/shubham/Development/llvm-project")
 !3 = !{i32 2, !"Debug Info Version", i32 3}
 !7 = !{i32 7, !"frame-pointer", i32 1}
-!9 = distinct !DISubprogram( unit: !0, retainedNodes: !14)
+!9 = distinct !DISubprogram( unit: !0, retainedNodes: !14, type: !28)
 !13 = !DIBasicType()
 !14 = !{}
 !15 = !DILocalVariable( scope: !9, type: !13)
-!19 = distinct !DISubprogram( unit: !0, retainedNodes: !20)
+!19 = distinct !DISubprogram( unit: !0, retainedNodes: !20, type: !28)
 !20 = !{}
 !23 = !DILocation( scope: !9, inlinedAt: !24)
 !24 = distinct !DILocation( scope: !19)
 !25 = !DILocation( scope: !19)
-!26 = !DILocation( scope: !19)
\ No newline at end of file
+!26 = !DILocation( scope: !19)
+!27 = !{null}
+!28 = !DISubroutineType(types: !27)
diff --git a/llvm/test/Transforms/AddDiscriminators/dbg-declare-discriminator.ll b/llvm/test/Transforms/AddDiscriminators/dbg-declare-discriminator.ll
index 6ef491684d6dd..a54580389fb2b 100644
--- a/llvm/test/Transforms/AddDiscriminators/dbg-declare-discriminator.ll
+++ b/llvm/test/Transforms/AddDiscriminators/dbg-declare-discriminator.ll
@@ -20,13 +20,15 @@ define void @test_valid_metadata() {
 !0 = !{i32 2, !"Dwarf Version", i32 4}
 !1 = !{i32 2, !"Debug Info Version", i32 3}
 !2 = !DILocalVariable(scope: !3)
-!3 = distinct !DISubprogram(scope: null, file: !4, isLocal: false, isDefinition: true, isOptimized: false, unit: !12)
+!3 = distinct !DISubprogram(scope: null, file: !4, isLocal: false, isDefinition: true, isOptimized: false, unit: !12, type: !14)
 !4 = !DIFile(filename: "a.cpp", directory: "/tmp")
 !5 = !DIExpression()
 !6 = !DILocation(line: 0, scope: !3, inlinedAt: !7)
 !7 = distinct !DILocation(line: 0, scope: !8)
-!8 = distinct !DISubprogram(linkageName: "test_valid_metadata", scope: null, isLocal: false, isDefinition: true, isOptimized: false, unit: !12)
+!8 = distinct !DISubprogram(linkageName: "test_valid_metadata", scope: null, isLocal: false, isDefinition: true, isOptimized: false, unit: !12, type: !14)
 !9 = !DILocalVariable(scope: !10)
-!10 = distinct !DISubprogram(scope: null, file: !4, isLocal: false, isDefinition: true, isOptimized: false, unit: !12)
+!10 = distinct !DISubprogram(scope: null, file: !4, isLocal: false, isDefinition: true, isOptimized: false, unit: !12, type: !14)
 !11 = !DILocation(line: 0, scope: !10)
 !12 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.5 ", isOptimized: false, emissionKind: FullDebug, file: !4)
+!13 = !{null}
+!14 = !DISubroutineType(types: !13)
diff --git a/llvm/test/Transforms/GlobalDCE/global_ctors.ll b/llvm/test/Transforms/GlobalDCE/global_ctors.ll
index e9dd944b98dfe..a89bc4197c68a 100644
--- a/llvm/test/Transforms/GlobalDCE/global_ctors.ll
+++ b/llvm/test/Transforms/GlobalDCE/global_ctors.ll
@@ -32,6 +32,8 @@ declare void @llvm.dbg.value(metadata, metadata, metadata)
 !0 = !{i32 2, !"Debug Info Version", i32 3}
 !1 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !2, emissionKind: FullDebug)
 !2 = !DIFile(filename: "filename", directory: "directory")
-!3 = distinct !DISubprogram(name: "h1", unit: !1)
+!3 = distinct !DISubprogram(name: "h1", unit: !1, type: !7)
 !4 = !DILocalVariable(name: "b", arg: 1, scope: !3)
 !5 = !DILocation(scope: !3)
+!6 = !{null}
+!7 = !DISubroutineType(types: !6)
diff --git a/llvm/test/Transforms/Inline/ignore-debug-info.ll b/llvm/test/Transforms/Inline/ignore-debug-info.ll
index 2187520a475da..c71b629e69799 100644
--- a/llvm/test/Transforms/Inline/ignore-debug-info.ll
+++ b/llvm/test/Transforms/Inline/ignore-debug-info.ll
@@ -53,4 +53,6 @@ attributes #0 = { nounwind readnone }
 !3 = !{i32 2, !"Dwarf Version", i32 4}
 !4 = !{i32 1, !"Debug Info Version", i32 3}
 !5 = !{!""}
-!6 = distinct !DISubprogram(unit: !0)
+!6 = distinct !DISubprogram(unit: !0, type: !8)
+!7 = !{null}
+!8 = !DISubroutineType(types: !7)
diff --git a/llvm/test/Transforms/InstCombine/debuginfo-scalable-typesize.ll b/llvm/test/Transforms/InstCombine/debuginfo-scalable-typesize.ll
index b2e78f1eff002..a3ce78b11fe1d 100644
--- a/llvm/test/Transforms/InstCombine/debuginfo-scalable-typesize.ll
+++ b/llvm/test/Transforms/InstCombine/debuginfo-scalable-typesize.ll
@@ -32,5 +32,7 @@ declare void @llvm.dbg.declare(metadata, metadata, metadata)
 !1 = !DIFile(filename: "/tmp/test.c", directory: "/tmp/")
 !2 = !{i32 2, !"Debug Info Version", i32 3}
 !3 = !DILocalVariable(scope: !4)
-!4 = distinct !DISubprogram(unit: !0)
+!4 = distinct !DISubprogram(unit: !0, type: !7)
 !5 = !DILocation(scope: !4)
+!6 = !{null}
+!7 = !DISubroutineType(types: !6)
diff --git a/llvm/test/Transforms/LoopStrengthReduce/pr12018.ll b/llvm/test/Transforms/LoopStrengthReduce/pr12018.ll
index 78fef12d28750..c95aaa3d1c2b4 100644
--- a/llvm/test/Transforms/LoopStrengthReduce/pr12018.ll
+++ b/llvm/test/Transforms/LoopStrengthReduce/pr12018.ll
@@ -35,4 +35,6 @@ declare ptr @_ZN8nsTArray4Hdr2Ev()
 declare void @llvm.dbg.value(metadata, metadata, metadata) nounwind readnone
 
 !0 = !DILocalVariable(scope: !1)
-!1 = distinct !DISubprogram()
+!1 = distinct !DISubprogram(type: !3)
+!2 = !{null}
+!3 = !DISubroutineType(types: !2)
diff --git a/llvm/test/Transforms/ObjCARC/basic.ll b/llvm/test/Transforms/ObjCARC/basic.ll
index aa0c53b4f4851..24f2862ffe5c7 100644
--- a/llvm/test/Transforms/ObjCARC/basic.ll
+++ b/llvm/test/Transforms/ObjCARC/basic.ll
@@ -2944,7 +2944,7 @@ define void @test68(ptr %a, ptr %b) {
 
 !0 = !{}
 !1 = !{i32 1, !"Debug Info Version", i32 3}
-!2 = distinct !DISubprogram(unit: !3)
+!2 = distinct !DISubprogram(unit: !3, type: !7)
 !3 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang",
                              file: !4,
                              isOptimized: true, flags: "-O2",
@@ -2954,3 +2954,5 @@ define void @test68(ptr %a, ptr %b) {
 
 ; CHECK: attributes [[NUW]] = { nounwind }
 ; CHECK: ![[RELEASE]] = !{}
+!6 = !{null}
+!7 = !DISubroutineType(types: !6)
diff --git a/llvm/test/Transforms/SampleProfile/nodebug.ll b/llvm/test/Transforms/SampleProfile/nodebug.ll
index dc516108b0d6d..ddf655a2d4da5 100644
--- a/llvm/test/Transforms/SampleProfile/nodebug.ll
+++ b/llvm/test/Transforms/SampleProfile/nodebug.ll
@@ -16,5 +16,7 @@ define void @bar() {
 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1)
 !1 = !DIFile(filename: "t", directory: "/tmp/")
 !2 = !{i32 2, !"Debug Info Version", i32 3}
-!3 = distinct !DISubprogram(name: "a", scope: !1, file: !1, line: 10, unit: !0)
+!3 = distinct !DISubprogram(name: "a", scope: !1, file: !1, line: 10, unit: !0, type: !6)
 !4 = !DILocation(line: 10, scope: !3)
+!5 = !{null}
+!6 = !DISubroutineType(types: !5)
diff --git a/llvm/test/Transforms/SampleProfile/summary.ll b/llvm/test/Transforms/SampleProfile/summary.ll
index ea27cc582bf8b..fdd5363acd8a4 100644
--- a/llvm/test/Transforms/SampleProfile/summary.ll
+++ b/llvm/test/Transforms/SampleProfile/summary.ll
@@ -19,8 +19,10 @@ entry:
 ; CHECK-DAG: {{![0-9]+}} = !{!"NumFunctions", i64 3}
 ; CHECK-DAG: {{![0-9]+}} = !{!"MaxFunctionCount", i64 3}
 
-!1 = distinct !DISubprogram(name: "bar")
+!1 = distinct !DISubprogram(name: "bar", type: !7)
 !2 = !DILocation(line: 2, scope: !2)
-!3 = distinct !DISubprogram(name: "baz")
+!3 = distinct !DISubprogram(name: "baz", type: !7)
 !4 = !DILocation(line: 1, scope: !4)
 !5 = !DILocation(line: 2, scope: !5)
+!6 = !{null}
+!7 = !DISubroutineType(types: !6)
diff --git a/llvm/test/Transforms/SimplifyCFG/X86/sink-common-code.ll b/llvm/test/Transforms/SimplifyCFG/X86/sink-common-code.ll
index 6129e3b957e17..8daa2334a4a68 100644
--- a/llvm/test/Transforms/SimplifyCFG/X86/sink-common-code.ll
+++ b/llvm/test/Transforms/SimplifyCFG/X86/sink-common-code.ll
@@ -510,7 +510,7 @@ declare void @llvm.dbg.value(metadata, metadata, metadata)
 !5 = !{i32 2, !"Dwarf Version", i32 4}
 !6 = !{i32 2, !"Debug Info Version", i32 3}
 !7 = distinct !DICompileUnit(language: DW_LANG_C99, file: !10)
-!8 = distinct !DISubprogram(name: "foo", unit: !7)
+!8 = distinct !DISubprogram(name: "foo", unit: !7, type: !14)
 !9 = !DILocalVariable(name: "b", line: 1, arg: 2, scope: !8)
 !10 = !DIFile(filename: "a.c", directory: "a/b")
 !11 = !DILocation(line: 1, column: 14, scope: !8)
@@ -2181,3 +2181,5 @@ declare void @dummy()
 declare void @use.ptr(ptr)
 
 !12 = !{i32 1}
+!13 = !{null}
+!14 = !DISubroutineType(types: !13)
diff --git a/llvm/test/Transforms/SimplifyCFG/preserve-llvm-loop-metadata.ll b/llvm/test/Transforms/SimplifyCFG/preserve-llvm-loop-metadata.ll
index a95b6ec15b129..8b3bdbee2249c 100644
--- a/llvm/test/Transforms/SimplifyCFG/preserve-llvm-loop-metadata.ll
+++ b/llvm/test/Transforms/SimplifyCFG/preserve-llvm-loop-metadata.ll
@@ -152,7 +152,7 @@ while.end:                                        ; preds = %while.cond
 !4 = !{!"llvm.loop.mustprogress"}
 !5 = distinct !{!5, !4, !6}
 !6 = !{!"llvm.loop.unroll.enable"}
-!7 = distinct !DISubprogram(name: "test3", scope: !8, file: !8, spFlags: DISPFlagDefinition, unit: !9)
+!7 = distinct !DISubprogram(name: "test3", scope: !8, file: !8, spFlags: DISPFlagDefinition, unit: !9, type: !15)
 !8 = !DIFile(filename: "preserve-llvm-loop-metadata.ll", directory: "/")
 !9 = distinct !DICompileUnit(language: DW_LANG_C99, file: !8, isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug)
 !10 = distinct !{!10, !11, !13}
@@ -167,3 +167,5 @@ while.end:                                        ; preds = %while.cond
 ; CHECK: !5 = distinct !{!5, !4, !6}
 ; CHECK: !6 = !{!"llvm.loop.unroll.enable"}
 ; CHECK-NOT: !10 = distinct !{!10, !11, !13}
+!14 = !{null}
+!15 = !DISubroutineType(types: !14)
diff --git a/llvm/test/Transforms/Util/store-first-op.ll b/llvm/test/Transforms/Util/store-first-op.ll
index 199a1ec6ce255..95d2469c9d19d 100644
--- a/llvm/test/Transforms/Util/store-first-op.ll
+++ b/llvm/test/Transforms/Util/store-first-op.ll
@@ -28,10 +28,12 @@ attributes #1 = { nounwind readnone }
 !1 = !DIFile(filename: "none", directory: ".")
 !2 = !{i32 2, !"Debug Info Version", i32 3}
 !3 = !DILocalVariable(name: "getU", scope: !4, file: !1, line: 25, type: !5)
-!4 = distinct !DISubprogram(name: "multiply64", linkageName: "_ZN4llvm13ScaledNumbers10multiply64Emm", scope: null, file: !1, line: 22, isLocal: false, isDefinition: true, scopeLine: 23, flags: DIFlagPrototyped, isOptimized: true, unit: !0)
+!4 = distinct !DISubprogram(name: "multiply64", linkageName: "_ZN4llvm13ScaledNumbers10multiply64Emm", scope: null, file: !1, line: 22, isLocal: false, isDefinition: true, scopeLine: 23, flags: DIFlagPrototyped, isOptimized: true, unit: !0, type: !12)
 !5 = !DICompositeType(tag: DW_TAG_class_type, scope: !4, file: !1, line: 25, size: 8, align: 8)
 !6 = !DIExpression()
 !7 = !DILocation(line: 25, column: 8, scope: !4)
 !8 = !{!10, !10, i64 0}
 !9 = !{i64 0}
 !10 = !{!"scalar type", !9}
+!11 = !{null}
+!12 = !DISubroutineType(types: !11)
diff --git a/llvm/test/Transforms/WholeProgramDevirt/devirt-metadata.ll b/llvm/test/Transforms/WholeProgramDevirt/devirt-metadata.ll
index d8781d5686b53..1e6fc4416ac1e 100644
--- a/llvm/test/Transforms/WholeProgramDevirt/devirt-metadata.ll
+++ b/llvm/test/Transforms/WholeProgramDevirt/devirt-metadata.ll
@@ -52,13 +52,14 @@ declare void @llvm.assume(i1)
 !2 = !{i32 2, !"Dwarf Version", i32 4}
 !3 = !{i32 2, !"Debug Info Version", i32 3}
 !4 = !{!"clang version 4.0.0 (trunk 278098)"}
-!5 = distinct !DISubprogram(name: "call", linkageName: "_Z4callPv", scope: !1, file: !1, line: 29, isLocal: false, isDefinition: true, scopeLine: 9, flags: DIFlagPrototyped, isOptimized: false, unit: !0)
+!5 = distinct !DISubprogram(name: "call", linkageName: "_Z4callPv", scope: !1, file: !1, line: 29, isLocal: false, isDefinition: true, scopeLine: 9, flags: DIFlagPrototyped, isOptimized: false, unit: !0, type: !14)
 !6 = !DILocation(line: 30, column: 32, scope: !5)
-!7 = distinct !DISubprogram(name: "vf", linkageName: "_ZN3vt12vfEb", scope: !1, file: !1, line: 13, isLocal: false, isDefinition: true, scopeLine: 13, flags: DIFlagPrototyped, isOptimized: false, unit: !0)
+!7 = distinct !DISubprogram(name: "vf", linkageName: "_ZN3vt12vfEb", scope: !1, file: !1, line: 13, isLocal: false, isDefinition: true, scopeLine: 13, flags: DIFlagPrototyped, isOptimized: false, unit: !0, type: !14)
 !8 = !{i32 0, !"typeid"}
 
-!9 = distinct !DISubprogram(name: "call1", linkageName: "_Z5call1Pv", scope: !1, file: !1, line: 31, isLocal: false, isDefinition: true, scopeLine: 9, flags: DIFlagPrototyped, isOptimized: false, unit: !0)
+!9 = distinct !DISubprogram(name: "call1", linkageName: "_Z5call1Pv", scope: !1, file: !1, line: 31, isLocal: false, isDefinition: true, scopeLine: 9, flags: DIFlagPrototyped, isOptimized: false, unit: !0, type: !14)
 !10 = !DILocation(line: 35, column: 32, scope: !9)
-!11 = distinct !DISubprogram(name: "vf2", linkageName: "_ZN3vt13vf2Eb", scope: !1, file: !1, line: 23, isLocal: false, isDefinition: true, scopeLine: 23, flags: DIFlagPrototyped, isOptimized: false, unit: !0)
+!11 = distinct !DISubprogram(name: "vf2", linkageName: "_ZN3vt13vf2Eb", scope: !1, file: !1, line: 23, isLocal: false, isDefinition: true, scopeLine: 23, flags: DIFlagPrototyped, isOptimized: false, unit: !0, type: !14)
 !12 = !{i32 0, !"typeid1"}
-
+!13 = !{null}
+!14 = !DISubroutineType(types: !13)
diff --git a/llvm/test/Verifier/DISubprogram-type.ll b/llvm/test/Verifier/DISubprogram-type.ll
index 55a2082d68cfa..df934b9a6250c 100644
--- a/llvm/test/Verifier/DISubprogram-type.ll
+++ b/llvm/test/Verifier/DISubprogram-type.ll
@@ -1,47 +1,32 @@
-; Verify that DISubprogram requires a non-null DISubroutineType for its
-; `type:` field. See https://github.com/llvm/llvm-project/issues/186557.
+; Verify that DISubprogram rejects a non-DISubroutineType value for its `type:`
+; field.  Missing/null `type:` is now rejected at parse time (see
+; llvm/test/Assembler/disubprogram-type-required.ll).
+; See https://github.com/llvm/llvm-project/issues/186557.
 
 ; RUN: llvm-as -disable-output < %s 2>&1 | FileCheck %s
 
-; CHECK: DISubprogram requires a non-null type
-; CHECK-NEXT: ![[MISSING:[0-9]+]] = distinct !DISubprogram(name: "missing_type"
-; CHECK: DISubprogram requires a non-null type
-; CHECK-NEXT: ![[NULL:[0-9]+]] = distinct !DISubprogram(name: "null_type"
 ; CHECK: invalid subroutine type
 ; CHECK-NEXT: ![[INVALID:[0-9]+]] = distinct !DISubprogram(name: "invalid_type"
-; CHECK-NEXT: !{{[0-9]+}} = !DIFile(filename: "x.c", directory: "/")
 ; CHECK: warning: ignoring invalid debug info
 ; CHECK-NOT: valid_void_type
 
-define void @missing_type() !dbg !4 {
+define void @invalid_type() !dbg !4 {
   ret void, !dbg !5
 }
 
-define void @null_type() !dbg !7 {
-  ret void, !dbg !8
-}
-
-define void @invalid_type() !dbg !9 {
-  ret void, !dbg !10
-}
-
-define void @valid_void_type() !dbg !11 {
-  ret void, !dbg !12
+define void @valid_void_type() !dbg !6 {
+  ret void, !dbg !7
 }
 
 !llvm.dbg.cu = !{!0}
-!llvm.module.flags = !{!13}
+!llvm.module.flags = !{!8}
 
 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", emissionKind: FullDebug)
 !1 = !DIFile(filename: "x.c", directory: "/")
 !2 = !{null}
 !3 = !DISubroutineType(types: !2)
-!4 = distinct !DISubprogram(name: "missing_type", scope: !1, file: !1, line: 1, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !0)
+!4 = distinct !DISubprogram(name: "invalid_type", scope: !1, file: !1, line: 1, type: !1, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !0)
 !5 = !DILocation(line: 1, column: 1, scope: !4)
-!7 = distinct !DISubprogram(name: "null_type", scope: !1, file: !1, line: 2, type: null, scopeLine: 2, spFlags: DISPFlagDefinition, unit: !0)
-!8 = !DILocation(line: 2, column: 1, scope: !7)
-!9 = distinct !DISubprogram(name: "invalid_type", scope: !1, file: !1, line: 3, type: !1, scopeLine: 3, spFlags: DISPFlagDefinition, unit: !0)
-!10 = !DILocation(line: 3, column: 1, scope: !9)
-!11 = distinct !DISubprogram(name: "valid_void_type", scope: !1, file: !1, line: 4, type: !3, scopeLine: 4, spFlags: DISPFlagDefinition, unit: !0)
-!12 = !DILocation(line: 4, column: 1, scope: !11)
-!13 = !{i32 1, !"Debug Info Version", i32 3}
+!6 = distinct !DISubprogram(name: "valid_void_type", scope: !1, file: !1, line: 2, type: !3, scopeLine: 2, spFlags: DISPFlagDefinition, unit: !0)
+!7 = !DILocation(line: 2, column: 1, scope: !6)
+!8 = !{i32 1, !"Debug Info Version", i32 3}
diff --git a/llvm/test/Verifier/RemoveDI/blockbyref.ll b/llvm/test/Verifier/RemoveDI/blockbyref.ll
index 86321a6ae78e8..43d9c2db53768 100644
--- a/llvm/test/Verifier/RemoveDI/blockbyref.ll
+++ b/llvm/test/Verifier/RemoveDI/blockbyref.ll
@@ -13,6 +13,8 @@ entry:
 
 !llvm.module.flags = !{!0}
 !0 = !{i32 2, !"Debug Info Version", i32 3}
-!1 = distinct !DISubprogram()
+!1 = distinct !DISubprogram(type: !5)
 !2 = !DILocalVariable(scope: !1, type: !3)
 !3 = !DICompositeType(tag: DW_TAG_structure_type, flags: DIFlagReservedBit4)
+!4 = !{null}
+!5 = !DISubroutineType(types: !4)
diff --git a/llvm/test/Verifier/RemoveDI/fnarg-debuginfo.ll b/llvm/test/Verifier/RemoveDI/fnarg-debuginfo.ll
index db1a9a8ba1894..e821ca264abba 100644
--- a/llvm/test/Verifier/RemoveDI/fnarg-debuginfo.ll
+++ b/llvm/test/Verifier/RemoveDI/fnarg-debuginfo.ll
@@ -17,10 +17,12 @@ entry:
 
 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", emissionKind: FullDebug)
 !1 = !DIFile(filename: "x.c", directory: "/")
-!2 = distinct !DISubprogram(name: "foo", scope: !0, isDefinition: true, unit: !0)
+!2 = distinct !DISubprogram(name: "foo", scope: !0, isDefinition: true, unit: !0, type: !10)
 !3 = !DILocalVariable(name: "a", arg: 1, scope: !2, file: !1, line: 1, type: !5)
 !4 = !DILocalVariable(name: "b", arg: 1, scope: !2, file: !1, line: 1, type: !5)
 !5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
 !6 = !DILocation(line: 1, scope: !2)
 !7 = !{i32 2, !"Dwarf Version", i32 4}
 !8 = !{i32 1, !"Debug Info Version", i32 3}
+!9 = !{null}
+!10 = !DISubroutineType(types: !9)
diff --git a/llvm/test/Verifier/RemoveDI/llvm.dbg.declare-address.ll b/llvm/test/Verifier/RemoveDI/llvm.dbg.declare-address.ll
index 9d400b892ce8c..52977b05918c8 100644
--- a/llvm/test/Verifier/RemoveDI/llvm.dbg.declare-address.ll
+++ b/llvm/test/Verifier/RemoveDI/llvm.dbg.declare-address.ll
@@ -13,4 +13,6 @@ entry:
 
 !llvm.module.flags = !{!0}
 !0 = !{i32 2, !"Debug Info Version", i32 3}
-!1 = distinct !DISubprogram()
+!1 = distinct !DISubprogram(type: !3)
+!2 = !{null}
+!3 = !DISubroutineType(types: !2)
diff --git a/llvm/test/Verifier/RemoveDI/llvm.dbg.declare-expression.ll b/llvm/test/Verifier/RemoveDI/llvm.dbg.declare-expression.ll
index b52c15cb3f881..de6425958632b 100644
--- a/llvm/test/Verifier/RemoveDI/llvm.dbg.declare-expression.ll
+++ b/llvm/test/Verifier/RemoveDI/llvm.dbg.declare-expression.ll
@@ -13,4 +13,6 @@ entry:
 
 !llvm.module.flags = !{!0}
 !0 = !{i32 2, !"Debug Info Version", i32 3}
-!1 = distinct !DISubprogram()
+!1 = distinct !DISubprogram(type: !3)
+!2 = !{null}
+!3 = !DISubroutineType(types: !2)
diff --git a/llvm/test/Verifier/RemoveDI/llvm.dbg.declare-variable.ll b/llvm/test/Verifier/RemoveDI/llvm.dbg.declare-variable.ll
index db2b0e0a54e2b..1ba81d568aeb0 100644
--- a/llvm/test/Verifier/RemoveDI/llvm.dbg.declare-variable.ll
+++ b/llvm/test/Verifier/RemoveDI/llvm.dbg.declare-variable.ll
@@ -14,4 +14,6 @@ entry:
 
 !llvm.module.flags = !{!0}
 !0 = !{i32 2, !"Debug Info Version", i32 3}
-!1 = distinct !DISubprogram()
+!1 = distinct !DISubprogram(type: !3)
+!2 = !{null}
+!3 = !DISubroutineType(types: !2)
diff --git a/llvm/test/Verifier/RemoveDI/llvm.dbg.intrinsic-dbg-attachment.ll b/llvm/test/Verifier/RemoveDI/llvm.dbg.intrinsic-dbg-attachment.ll
index 1839821ab1407..db1f62c07da74 100644
--- a/llvm/test/Verifier/RemoveDI/llvm.dbg.intrinsic-dbg-attachment.ll
+++ b/llvm/test/Verifier/RemoveDI/llvm.dbg.intrinsic-dbg-attachment.ll
@@ -51,5 +51,7 @@ entry:
 
 !llvm.module.flags = !{!0}
 !0 = !{i32 2, !"Debug Info Version", i32 3}
-!1 = distinct !DISubprogram(name: "foo")
-!2 = distinct !DISubprogram(name: "bar")
+!1 = distinct !DISubprogram(name: "foo", type: !4)
+!2 = distinct !DISubprogram(name: "bar", type: !4)
+!3 = !{null}
+!4 = !DISubroutineType(types: !3)
diff --git a/llvm/test/Verifier/RemoveDI/llvm.dbg.value-expression.ll b/llvm/test/Verifier/RemoveDI/llvm.dbg.value-expression.ll
index cbd93c1ce6a4d..2fffac846ff9b 100644
--- a/llvm/test/Verifier/RemoveDI/llvm.dbg.value-expression.ll
+++ b/llvm/test/Verifier/RemoveDI/llvm.dbg.value-expression.ll
@@ -13,4 +13,6 @@ entry:
 
 !llvm.module.flags = !{!0}
 !0 = !{i32 2, !"Debug Info Version", i32 3}
-!1 = distinct !DISubprogram()
+!1 = distinct !DISubprogram(type: !3)
+!2 = !{null}
+!3 = !DISubroutineType(types: !2)
diff --git a/llvm/test/Verifier/RemoveDI/llvm.dbg.value-value.ll b/llvm/test/Verifier/RemoveDI/llvm.dbg.value-value.ll
index b6fcde250526b..dda2266288a33 100644
--- a/llvm/test/Verifier/RemoveDI/llvm.dbg.value-value.ll
+++ b/llvm/test/Verifier/RemoveDI/llvm.dbg.value-value.ll
@@ -14,4 +14,6 @@ entry:
 
 !llvm.module.flags = !{!0}
 !0 = !{i32 2, !"Debug Info Version", i32 3}
-!1 = distinct !DISubprogram()
+!1 = distinct !DISubprogram(type: !3)
+!2 = !{null}
+!3 = !DISubroutineType(types: !2)
diff --git a/llvm/test/Verifier/RemoveDI/llvm.dbg.value-variable.ll b/llvm/test/Verifier/RemoveDI/llvm.dbg.value-variable.ll
index 0a5fe79453d72..9d1ab304e8211 100644
--- a/llvm/test/Verifier/RemoveDI/llvm.dbg.value-variable.ll
+++ b/llvm/test/Verifier/RemoveDI/llvm.dbg.value-variable.ll
@@ -14,4 +14,6 @@ entry:
 
 !llvm.module.flags = !{!0}
 !0 = !{i32 2, !"Debug Info Version", i32 3}
-!1 = distinct !DISubprogram()
+!1 = distinct !DISubprogram(type: !3)
+!2 = !{null}
+!3 = !DISubroutineType(types: !2)
diff --git a/llvm/test/Verifier/blockbyref.ll b/llvm/test/Verifier/blockbyref.ll
index 735c79072c06c..3c44d6d209a99 100644
--- a/llvm/test/Verifier/blockbyref.ll
+++ b/llvm/test/Verifier/blockbyref.ll
@@ -14,6 +14,8 @@ declare void @llvm.dbg.declare(metadata, metadata, metadata)
 
 !llvm.module.flags = !{!0}
 !0 = !{i32 2, !"Debug Info Version", i32 3}
-!1 = distinct !DISubprogram()
+!1 = distinct !DISubprogram(type: !5)
 !2 = !DILocalVariable(scope: !1, type: !3)
 !3 = !DICompositeType(tag: DW_TAG_structure_type, flags: DIFlagReservedBit4)
+!4 = !{null}
+!5 = !DISubroutineType(types: !4)
diff --git a/llvm/test/Verifier/dbg-difile-crash.ll b/llvm/test/Verifier/dbg-difile-crash.ll
index bb57f6128d331..492a782d7d75d 100644
--- a/llvm/test/Verifier/dbg-difile-crash.ll
+++ b/llvm/test/Verifier/dbg-difile-crash.ll
@@ -11,4 +11,6 @@ define void @blah() !dbg !3 {
 !llvm.dbg.cu = !{!1}
 !1 = distinct !DICompileUnit(file: !2, language: DW_LANG_C99)
 !2 = !DIFile(filename: "file.c", directory: "/path/to/dir")
-!3 = distinct !DISubprogram(name: "blah", file: !1, unit: !1)
+!3 = distinct !DISubprogram(name: "blah", file: !1, unit: !1, type: !5)
+!4 = !{null}
+!5 = !DISubroutineType(types: !4)
diff --git a/llvm/test/Verifier/dbg-invalid-retaintypes.ll b/llvm/test/Verifier/dbg-invalid-retaintypes.ll
index 87484ba3faa0d..b289f5d3e2306 100644
--- a/llvm/test/Verifier/dbg-invalid-retaintypes.ll
+++ b/llvm/test/Verifier/dbg-invalid-retaintypes.ll
@@ -5,6 +5,8 @@
 !llvm.module.flags = !{!3}
 
 !0 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang version 3.0 (trunk 131941)", isOptimized: true, emissionKind: FullDebug, file: !2, retainedTypes: !1)
-!1 = distinct !DISubprogram(name: "main", line: 1, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 1, scope: !2)
+!1 = distinct !DISubprogram(name: "main", line: 1, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 1, scope: !2, type: !5)
 !2 = !DIFile(filename: "/davide/test", directory: "/")
 !3 = !{i32 1, !"Debug Info Version", i32 3}
+!4 = !{null}
+!5 = !DISubroutineType(types: !4)
diff --git a/llvm/test/Verifier/dbg-line-without-file.ll b/llvm/test/Verifier/dbg-line-without-file.ll
index 9cc052911f65c..d8a452e3f0744 100644
--- a/llvm/test/Verifier/dbg-line-without-file.ll
+++ b/llvm/test/Verifier/dbg-line-without-file.ll
@@ -12,4 +12,6 @@ define void @foo() !dbg !3 {
 !0 = !{i32 2, !"Debug Info Version", i32 3}
 !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2)
 !2 = !DIFile(filename: "foo.c", directory: "")
-!3 = distinct !DISubprogram(name: "foo", scope: !1, line: 1, unit: !1)
+!3 = distinct !DISubprogram(name: "foo", scope: !1, line: 1, unit: !1, type: !5)
+!4 = !{null}
+!5 = !DISubroutineType(types: !4)
diff --git a/llvm/test/Verifier/dbg.ll b/llvm/test/Verifier/dbg.ll
index 32c46587070bb..20958e9ede0b1 100644
--- a/llvm/test/Verifier/dbg.ll
+++ b/llvm/test/Verifier/dbg.ll
@@ -17,4 +17,6 @@ exit:
 ; CHECK: warning: ignoring invalid debug info
 !llvm.module.flags = !{!0}
 !0 = !{i32 2, !"Debug Info Version", i32 3}
-!1 = distinct !DISubprogram()
+!1 = distinct !DISubprogram(type: !3)
+!2 = !{null}
+!3 = !DISubroutineType(types: !2)
diff --git a/llvm/test/Verifier/fnarg-debuginfo.ll b/llvm/test/Verifier/fnarg-debuginfo.ll
index 10d0710fcd5ef..341aa3be952fb 100644
--- a/llvm/test/Verifier/fnarg-debuginfo.ll
+++ b/llvm/test/Verifier/fnarg-debuginfo.ll
@@ -19,10 +19,12 @@ entry:
 
 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", emissionKind: FullDebug)
 !1 = !DIFile(filename: "x.c", directory: "/")
-!2 = distinct !DISubprogram(name: "foo", scope: !0, isDefinition: true, unit: !0)
+!2 = distinct !DISubprogram(name: "foo", scope: !0, isDefinition: true, unit: !0, type: !10)
 !3 = !DILocalVariable(name: "a", arg: 1, scope: !2, file: !1, line: 1, type: !5)
 !4 = !DILocalVariable(name: "b", arg: 1, scope: !2, file: !1, line: 1, type: !5)
 !5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
 !6 = !DILocation(line: 1, scope: !2)
 !7 = !{i32 2, !"Dwarf Version", i32 4}
 !8 = !{i32 1, !"Debug Info Version", i32 3}
+!9 = !{null}
+!10 = !DISubroutineType(types: !9)
diff --git a/llvm/test/Verifier/func-dbg.ll b/llvm/test/Verifier/func-dbg.ll
index e6518a4a41ea6..967c92025f33b 100644
--- a/llvm/test/Verifier/func-dbg.ll
+++ b/llvm/test/Verifier/func-dbg.ll
@@ -18,8 +18,10 @@ entry:
 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !2, imports: !2)
 !1 = !DIFile(filename: "dwarf-test.c", directory: "test")
 !2 = !{}
-!4 = distinct !DISubprogram(name: "foo", scope: !0, isDefinition: true, unit: !0)
-!5 = distinct !DISubprogram(name: "bar", scope: !0, isDefinition: true, unit: !0)
+!4 = distinct !DISubprogram(name: "foo", scope: !0, isDefinition: true, unit: !0, type: !10)
+!5 = distinct !DISubprogram(name: "bar", scope: !0, isDefinition: true, unit: !0, type: !10)
 !6 = !DILocation(line: 7, scope: !4)
 !7 = !{i32 2, !"Dwarf Version", i32 3}
 !8 = !{i32 1, !"Debug Info Version", i32 3}
+!9 = !{null}
+!10 = !DISubroutineType(types: !9)
diff --git a/llvm/test/Verifier/llvm.dbg.declare-address.ll b/llvm/test/Verifier/llvm.dbg.declare-address.ll
index 251526b4c321b..30bcf9b6976c4 100644
--- a/llvm/test/Verifier/llvm.dbg.declare-address.ll
+++ b/llvm/test/Verifier/llvm.dbg.declare-address.ll
@@ -15,4 +15,6 @@ declare void @llvm.dbg.declare(metadata, metadata, metadata)
 
 !llvm.module.flags = !{!0}
 !0 = !{i32 2, !"Debug Info Version", i32 3}
-!1 = distinct !DISubprogram()
+!1 = distinct !DISubprogram(type: !3)
+!2 = !{null}
+!3 = !DISubroutineType(types: !2)
diff --git a/llvm/test/Verifier/llvm.dbg.declare-expression.ll b/llvm/test/Verifier/llvm.dbg.declare-expression.ll
index de65bb570677e..7a3389c162a2e 100644
--- a/llvm/test/Verifier/llvm.dbg.declare-expression.ll
+++ b/llvm/test/Verifier/llvm.dbg.declare-expression.ll
@@ -14,4 +14,6 @@ declare void @llvm.dbg.declare(metadata, metadata, metadata)
 
 !llvm.module.flags = !{!0}
 !0 = !{i32 2, !"Debug Info Version", i32 3}
-!1 = distinct !DISubprogram()
+!1 = distinct !DISubprogram(type: !3)
+!2 = !{null}
+!3 = !DISubroutineType(types: !2)
diff --git a/llvm/test/Verifier/llvm.dbg.declare-variable.ll b/llvm/test/Verifier/llvm.dbg.declare-variable.ll
index 601fab190d36b..62784fde98c86 100644
--- a/llvm/test/Verifier/llvm.dbg.declare-variable.ll
+++ b/llvm/test/Verifier/llvm.dbg.declare-variable.ll
@@ -18,4 +18,6 @@ declare void @llvm.dbg.declare(metadata, metadata, metadata)
 
 !llvm.module.flags = !{!0}
 !0 = !{i32 2, !"Debug Info Version", i32 3}
-!1 = distinct !DISubprogram()
+!1 = distinct !DISubprogram(type: !3)
+!2 = !{null}
+!3 = !DISubroutineType(types: !2)
diff --git a/llvm/test/Verifier/llvm.dbg.intrinsic-dbg-attachment.ll b/llvm/test/Verifier/llvm.dbg.intrinsic-dbg-attachment.ll
index b1e22b20d0864..5797d3a9f33e0 100644
--- a/llvm/test/Verifier/llvm.dbg.intrinsic-dbg-attachment.ll
+++ b/llvm/test/Verifier/llvm.dbg.intrinsic-dbg-attachment.ll
@@ -55,5 +55,7 @@ declare void @llvm.dbg.declare(metadata, metadata, metadata)
 
 !llvm.module.flags = !{!0}
 !0 = !{i32 2, !"Debug Info Version", i32 3}
-!1 = distinct !DISubprogram(name: "foo")
-!2 = distinct !DISubprogram(name: "bar")
+!1 = distinct !DISubprogram(name: "foo", type: !4)
+!2 = distinct !DISubprogram(name: "bar", type: !4)
+!3 = !{null}
+!4 = !DISubroutineType(types: !3)
diff --git a/llvm/test/Verifier/llvm.dbg.value-expression.ll b/llvm/test/Verifier/llvm.dbg.value-expression.ll
index 92fd2add700ed..fcf808d9a651e 100644
--- a/llvm/test/Verifier/llvm.dbg.value-expression.ll
+++ b/llvm/test/Verifier/llvm.dbg.value-expression.ll
@@ -14,4 +14,6 @@ declare void @llvm.dbg.value(metadata, i64, metadata, metadata)
 
 !llvm.module.flags = !{!0}
 !0 = !{i32 2, !"Debug Info Version", i32 3}
-!1 = distinct !DISubprogram()
+!1 = distinct !DISubprogram(type: !3)
+!2 = !{null}
+!3 = !DISubroutineType(types: !2)
diff --git a/llvm/test/Verifier/llvm.dbg.value-value.ll b/llvm/test/Verifier/llvm.dbg.value-value.ll
index c390e530653cd..d123532a75d26 100644
--- a/llvm/test/Verifier/llvm.dbg.value-value.ll
+++ b/llvm/test/Verifier/llvm.dbg.value-value.ll
@@ -15,4 +15,6 @@ declare void @llvm.dbg.value(metadata, i64, metadata, metadata)
 
 !llvm.module.flags = !{!0}
 !0 = !{i32 2, !"Debug Info Version", i32 3}
-!1 = distinct !DISubprogram()
+!1 = distinct !DISubprogram(type: !3)
+!2 = !{null}
+!3 = !DISubroutineType(types: !2)
diff --git a/llvm/test/Verifier/llvm.dbg.value-variable.ll b/llvm/test/Verifier/llvm.dbg.value-variable.ll
index 603a4b5c47e7d..8bbc12a21621f 100644
--- a/llvm/test/Verifier/llvm.dbg.value-variable.ll
+++ b/llvm/test/Verifier/llvm.dbg.value-variable.ll
@@ -14,4 +14,6 @@ declare void @llvm.dbg.value(metadata, i64, metadata, metadata)
 
 !llvm.module.flags = !{!0}
 !0 = !{i32 2, !"Debug Info Version", i32 3}
-!1 = distinct !DISubprogram()
+!1 = distinct !DISubprogram(type: !3)
+!2 = !{null}
+!3 = !DISubroutineType(types: !2)
diff --git a/llvm/test/Verifier/llvm.loop.ll b/llvm/test/Verifier/llvm.loop.ll
index 3475abb673ab9..eb270863ea1b9 100644
--- a/llvm/test/Verifier/llvm.loop.ll
+++ b/llvm/test/Verifier/llvm.loop.ll
@@ -18,11 +18,13 @@ entry:
 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !2, imports: !2)
 !1 = !DIFile(filename: "dwarf-test.c", directory: "test")
 !2 = !{}
-!4 = distinct !DISubprogram(name: "foo", scope: !0, isDefinition: true, unit: !0)
-!5 = distinct !DISubprogram(name: "bar", scope: !0, isDefinition: true, unit: !0)
+!4 = distinct !DISubprogram(name: "foo", scope: !0, isDefinition: true, unit: !0, type: !13)
+!5 = distinct !DISubprogram(name: "bar", scope: !0, isDefinition: true, unit: !0, type: !13)
 !6 = !DILocation(line: 7, scope: !4)
 !7 = !{i32 2, !"Dwarf Version", i32 3}
 !8 = !{i32 1, !"Debug Info Version", i32 3}
 !9 = !{!9, !10, !11}
 !10 = !DILocation(line: 1, scope: !5)
 !11 = !DILocation(line: 1, scope: !4)
+!12 = !{null}
+!13 = !DISubroutineType(types: !12)
diff --git a/llvm/test/Verifier/local-import-in-cu.ll b/llvm/test/Verifier/local-import-in-cu.ll
index c0cda1a1fa93e..6d71a087a2605 100644
--- a/llvm/test/Verifier/local-import-in-cu.ll
+++ b/llvm/test/Verifier/local-import-in-cu.ll
@@ -8,7 +8,9 @@
 !0 = !{i32 2, !"Debug Info Version", i32 3}
 !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, imports: !5)
 !2 = !DIFile(filename: "foo.c", directory: "")
-!3 = distinct !DISubprogram(name: "foo", scope: !1, file: !2, line: 1, unit: !1)
+!3 = distinct !DISubprogram(name: "foo", scope: !1, file: !2, line: 1, unit: !1, type: !8)
 !4 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !3, entity: !6)
 !5 = !{!4}
 !6 = !DINamespace(name: "M", scope: null)
+!7 = !{null}
+!8 = !DISubroutineType(types: !7)
diff --git a/llvm/test/Verifier/metadata-function-dbg.ll b/llvm/test/Verifier/metadata-function-dbg.ll
index 23ac6f31c9e1a..0dae64fc33903 100644
--- a/llvm/test/Verifier/metadata-function-dbg.ll
+++ b/llvm/test/Verifier/metadata-function-dbg.ll
@@ -37,6 +37,8 @@ define void @bar() !dbg !3 {
 !1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, retainedTypes: !5)
 !2 = !DIFile(filename: "t.c", directory: "/path/to/dir")
 !3 = !{}
-!4 = distinct !DISubprogram(name: "foo", scope: !1, file: !2, unit: !1)
+!4 = distinct !DISubprogram(name: "foo", scope: !1, file: !2, unit: !1, type: !8)
 !5 = !{!6}
-!6 = !DISubprogram(name: "f5", scope: !1, file: !2, unit: !1, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
+!6 = !DISubprogram(name: "f5", scope: !1, file: !2, unit: !1, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, type: !8)
+!7 = !{null}
+!8 = !DISubroutineType(types: !7)
diff --git a/llvm/test/Verifier/pr34325.ll b/llvm/test/Verifier/pr34325.ll
index fcc1f0b5300f3..077c0fbcf3bbd 100644
--- a/llvm/test/Verifier/pr34325.ll
+++ b/llvm/test/Verifier/pr34325.ll
@@ -14,6 +14,8 @@
 !3 = !DIFile(filename: "a", directory: "")
 !4 = !{!5}
 !5 = distinct !DICompositeType(tag: DW_TAG_class_type, scope: !6, file: !3, identifier: "patatino")
-!6 = distinct !DISubprogram(name: "b", scope: null, isLocal: false, isDefinition: true, isOptimized: false, unit: !2)
+!6 = distinct !DISubprogram(name: "b", scope: null, isLocal: false, isDefinition: true, isOptimized: false, unit: !2, type: !10)
 !7 = !{!0}
 !8 = !{i32 2, !"Debug Info Version", i32 3}
+!9 = !{null}
+!10 = !DISubroutineType(types: !9)

>From 1b62b76e7656e15124d4ccc9114ba31205f72d8e Mon Sep 17 00:00:00 2001
From: JiangNing <jiangninghx at foxmail.com>
Date: Thu, 7 May 2026 21:14:29 +0800
Subject: [PATCH 2/2] [DebugInfo] Fix mlir/test missing DISubprogram type

Add missing type: field to DISubprogram in
mlir/test/Target/LLVMIR/Import/global-variables.ll, missed by the
initial batch fix in the previous commit.

Co-Authored-By: Claude Sonnet 4.6 <noreply at anthropic.com>
---
 mlir/test/Target/LLVMIR/Import/global-variables.ll | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/mlir/test/Target/LLVMIR/Import/global-variables.ll b/mlir/test/Target/LLVMIR/Import/global-variables.ll
index 6ecead10e6327..899b32a30ebf4 100644
--- a/mlir/test/Target/LLVMIR/Import/global-variables.ll
+++ b/mlir/test/Target/LLVMIR/Import/global-variables.ll
@@ -295,11 +295,13 @@ define void @foo() {
 !0 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
 !1 = !DIFile(filename: "source.c", directory: "/path/to/file")
 !2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1)
-!3 = distinct !DISubprogram(name: "foo", scope: !2, file: !1, line: 5)
+!3 = distinct !DISubprogram(name: "foo", scope: !2, file: !1, line: 5, type: !9)
 !4 = !DIGlobalVariable(name: "foo", linkageName: "foo", scope: !3, file: !1, line: 7, type: !0, isLocal: true, isDefinition: false)
 !5 = !DIGlobalVariableExpression(var: !4, expr: !DIExpression(DW_OP_LLVM_fragment, 0, 16))
 !6 = !DIGlobalVariable(name: "bar", linkageName: "bar", scope: !3, file: !1, line: 8, type: !0, isLocal: true, isDefinition: false)
 !7 = !DIGlobalVariableExpression(var: !6, expr: !DIExpression(DW_OP_constu, 3, DW_OP_plus))
+!8 = !{null}
+!9 = !DISubroutineType(types: !8)
 !100 = !{i32 2, !"Debug Info Version", i32 3}
 !llvm.module.flags = !{!100}
 



More information about the Mlir-commits mailing list