Skip to content

[DebugInfo] Enforce DISubprogram type as required in LLParser#196299

Merged
Michael137 merged 1 commit into
llvm:mainfrom
JiangNingHX:disubprogram-type-llparser
May 13, 2026
Merged

[DebugInfo] Enforce DISubprogram type as required in LLParser#196299
Michael137 merged 1 commit into
llvm:mainfrom
JiangNingHX:disubprogram-type-llparser

Conversation

@JiangNingHX
Copy link
Copy Markdown
Contributor

Add a parse-time check so that LLParser treats the type: field of
DISubprogram as required and non-null. Attempting to assemble IR with
a missing or null type: now produces a clear parse-time error
("missing required field 'type'" or "'type' cannot be null") rather
than relying solely on the verifier warning added in #194556.

Update existing hand-written LLVM IR tests to supply a minimal valid
DISubroutineType where they are not intentionally testing malformed
debug info.

Scope. This patch covers the LLParser path only. Two entry points
are intentionally deferred:

  • MetadataLoader: pre-LLVM-5 bitcode legitimately stores null
    DISubprogram.type; auto-upgrading that field requires more careful
    backward-compatibility handling (see llvm/test/Bitcode/dityperefs-3.8.ll).
  • BitcodeWriter: IR written to bitcode has already passed the
    verifier, which guarantees a non-null type; no additional check is
    needed in the writer.

Follow-up to #194556.

@llvmorg-github-actions llvmorg-github-actions Bot added backend:ARM backend:AArch64 backend:AMDGPU backend:RISC-V backend:WebAssembly backend:X86 debuginfo llvm:globalisel PGO Profile Guided Optimizations llvm:instcombine Covers the InstCombine, InstSimplify and AggressiveInstCombine passes LTO Link time optimization (regular/full LTO or ThinLTO) llvm:analysis Includes value tracking, cost tables and constant folding llvm:transforms labels May 7, 2026
@llvmorg-github-actions
Copy link
Copy Markdown

llvmorg-github-actions Bot commented May 7, 2026

@llvm/pr-subscribers-mlir-llvm
@llvm/pr-subscribers-mlir
@llvm/pr-subscribers-debuginfo
@llvm/pr-subscribers-llvm-transforms
@llvm/pr-subscribers-llvm-analysis
@llvm/pr-subscribers-backend-aarch64
@llvm/pr-subscribers-backend-risc-v
@llvm/pr-subscribers-pgo
@llvm/pr-subscribers-llvm-globalisel

@llvm/pr-subscribers-backend-arm

Author: Jiang Ning (JiangNingHX)

Changes

Add a parse-time check so that LLParser treats the type: field of
DISubprogram as required and non-null. Attempting to assemble IR with
a missing or null type: now produces a clear parse-time error
("missing required field 'type'" or "'type' cannot be null") rather
than relying solely on the verifier warning added in #194556.

Update existing hand-written LLVM IR tests to supply a minimal valid
DISubroutineType where they are not intentionally testing malformed
debug info.

Scope. This patch covers the LLParser path only. Two entry points
are intentionally deferred:

  • MetadataLoader: pre-LLVM-5 bitcode legitimately stores null
    DISubprogram.type; auto-upgrading that field requires more careful
    backward-compatibility handling (see llvm/test/Bitcode/dityperefs-3.8.ll).
  • BitcodeWriter: IR written to bitcode has already passed the
    verifier, which guarantees a non-null type; no additional check is
    needed in the writer.

Follow-up to #194556.


Patch is 75.43 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/196299.diff

88 Files Affected:

  • (modified) llvm/lib/AsmParser/LLParser.cpp (+1-1)
  • (modified) llvm/test/Analysis/CostModel/X86/free-intrinsics.ll (+3-1)
  • (modified) llvm/test/Analysis/CostModel/free-intrinsics-datalayout.ll (+3-1)
  • (modified) llvm/test/Analysis/CostModel/free-intrinsics-no_info.ll (+3-1)
  • (added) llvm/test/Assembler/disubprogram-type-required.ll (+29)
  • (modified) llvm/test/Assembler/drop-debug-info-nonzero-alloca.ll (+3-1)
  • (modified) llvm/test/Assembler/invalid-diflag-bad.ll (+3-1)
  • (modified) llvm/test/Assembler/invalid-disubprogram-uniqued-definition.ll (+3-1)
  • (modified) llvm/test/CodeGen/AArch64/GlobalISel/fconstant-dbg-loc.ll (+3-1)
  • (modified) llvm/test/CodeGen/AArch64/sdag-no-typesize-warnings-regandsizes.ll (+3-1)
  • (modified) llvm/test/CodeGen/AArch64/selectiondag-order.ll (+3-1)
  • (modified) llvm/test/CodeGen/AMDGPU/simplify-libcalls2.ll (+3-1)
  • (modified) llvm/test/CodeGen/ARM/2009-10-16-Scope.ll (+3-1)
  • (modified) llvm/test/CodeGen/ARM/analyze-branch-bkpt.ll (+5-3)
  • (modified) llvm/test/CodeGen/Generic/dbg_value.ll (+3-1)
  • (modified) llvm/test/CodeGen/MIR/X86/fixed-stack-di.mir (+3-1)
  • (modified) llvm/test/CodeGen/MIR/X86/invalid-metadata-node-type.mir (+3-1)
  • (modified) llvm/test/CodeGen/RISCV/rvv/get-vlen-debugloc.mir (+3-1)
  • (modified) llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/2009-10-16-Scope.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/AMX/amx-ldtilecfg-insert.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/GlobalISel/regbankselect-dbg-value-physreg-crash.mir (+3-1)
  • (modified) llvm/test/CodeGen/X86/StackColoring-dbg.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/addrsig.ll (+4-2)
  • (modified) llvm/test/CodeGen/X86/dbg-changes-codegen.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/frame-lowering-debug-intrinsic-2.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/frame-lowering-debug-intrinsic.ll (+4-2)
  • (modified) llvm/test/CodeGen/X86/lrshrink.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/machine-trace-metrics-crash.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/opt_phis.mir (+3-1)
  • (modified) llvm/test/CodeGen/X86/pr149841.ll (+3-2)
  • (modified) llvm/test/CodeGen/X86/pr57673.mir (+3-1)
  • (modified) llvm/test/CodeGen/X86/selectiondag-dbgvalue-null-crash.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/selectiondag-order.ll (+3-1)
  • (modified) llvm/test/DebugInfo/AArch64/abstract-sp-unit.ll (+2-2)
  • (modified) llvm/test/DebugInfo/AArch64/merge-locations-legalizer.mir (+3-1)
  • (modified) llvm/test/DebugInfo/Generic/split-dwarf-local-import2.ll (+3-3)
  • (modified) llvm/test/DebugInfo/MIR/X86/regcoalescing-clears-dead-dbgvals.mir (+3-1)
  • (modified) llvm/test/DebugInfo/X86/empty-struct-no-crash.ll (+4-2)
  • (modified) llvm/test/LTO/X86/Inputs/strip-debug-info-bar.ll (+3-2)
  • (modified) llvm/test/LTO/X86/Inputs/type-mapping-bug2.ll (+3-1)
  • (modified) llvm/test/LTO/X86/Inputs/type-mapping-bug3.ll (+3-1)
  • (modified) llvm/test/LTO/X86/pr38046.ll (+3-1)
  • (modified) llvm/test/LTO/X86/type-mapping-bug2.ll (+3-2)
  • (modified) llvm/test/Linker/2009-09-03-mdnode.ll (+3-1)
  • (modified) llvm/test/Linker/2009-09-03-mdnode2.ll (+3-1)
  • (modified) llvm/test/Linker/odr.ll (+3-1)
  • (modified) llvm/test/Other/dropped-var-stats.ll (+5-3)
  • (modified) llvm/test/Transforms/AddDiscriminators/dbg-declare-discriminator.ll (+5-3)
  • (modified) llvm/test/Transforms/GlobalDCE/global_ctors.ll (+3-1)
  • (modified) llvm/test/Transforms/Inline/ignore-debug-info.ll (+3-1)
  • (modified) llvm/test/Transforms/InstCombine/debuginfo-scalable-typesize.ll (+3-1)
  • (modified) llvm/test/Transforms/LoopStrengthReduce/pr12018.ll (+3-1)
  • (modified) llvm/test/Transforms/ObjCARC/basic.ll (+3-1)
  • (modified) llvm/test/Transforms/SampleProfile/nodebug.ll (+3-1)
  • (modified) llvm/test/Transforms/SampleProfile/summary.ll (+4-2)
  • (modified) llvm/test/Transforms/SimplifyCFG/X86/sink-common-code.ll (+3-1)
  • (modified) llvm/test/Transforms/SimplifyCFG/preserve-llvm-loop-metadata.ll (+3-1)
  • (modified) llvm/test/Transforms/Util/store-first-op.ll (+3-1)
  • (modified) llvm/test/Transforms/WholeProgramDevirt/devirt-metadata.ll (+6-5)
  • (modified) llvm/test/Verifier/DISubprogram-type.ll (+12-27)
  • (modified) llvm/test/Verifier/RemoveDI/blockbyref.ll (+3-1)
  • (modified) llvm/test/Verifier/RemoveDI/fnarg-debuginfo.ll (+3-1)
  • (modified) llvm/test/Verifier/RemoveDI/llvm.dbg.declare-address.ll (+3-1)
  • (modified) llvm/test/Verifier/RemoveDI/llvm.dbg.declare-expression.ll (+3-1)
  • (modified) llvm/test/Verifier/RemoveDI/llvm.dbg.declare-variable.ll (+3-1)
  • (modified) llvm/test/Verifier/RemoveDI/llvm.dbg.intrinsic-dbg-attachment.ll (+4-2)
  • (modified) llvm/test/Verifier/RemoveDI/llvm.dbg.value-expression.ll (+3-1)
  • (modified) llvm/test/Verifier/RemoveDI/llvm.dbg.value-value.ll (+3-1)
  • (modified) llvm/test/Verifier/RemoveDI/llvm.dbg.value-variable.ll (+3-1)
  • (modified) llvm/test/Verifier/blockbyref.ll (+3-1)
  • (modified) llvm/test/Verifier/dbg-difile-crash.ll (+3-1)
  • (modified) llvm/test/Verifier/dbg-invalid-retaintypes.ll (+3-1)
  • (modified) llvm/test/Verifier/dbg-line-without-file.ll (+3-1)
  • (modified) llvm/test/Verifier/dbg.ll (+3-1)
  • (modified) llvm/test/Verifier/fnarg-debuginfo.ll (+3-1)
  • (modified) llvm/test/Verifier/func-dbg.ll (+4-2)
  • (modified) llvm/test/Verifier/llvm.dbg.declare-address.ll (+3-1)
  • (modified) llvm/test/Verifier/llvm.dbg.declare-expression.ll (+3-1)
  • (modified) llvm/test/Verifier/llvm.dbg.declare-variable.ll (+3-1)
  • (modified) llvm/test/Verifier/llvm.dbg.intrinsic-dbg-attachment.ll (+4-2)
  • (modified) llvm/test/Verifier/llvm.dbg.value-expression.ll (+3-1)
  • (modified) llvm/test/Verifier/llvm.dbg.value-value.ll (+3-1)
  • (modified) llvm/test/Verifier/llvm.dbg.value-variable.ll (+3-1)
  • (modified) llvm/test/Verifier/llvm.loop.ll (+4-2)
  • (modified) llvm/test/Verifier/local-import-in-cu.ll (+3-1)
  • (modified) llvm/test/Verifier/metadata-function-dbg.ll (+4-2)
  • (modified) llvm/test/Verifier/pr34325.ll (+3-1)
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...
[truncated]

@llvmorg-github-actions
Copy link
Copy Markdown

@llvm/pr-subscribers-backend-amdgpu

Author: Jiang Ning (JiangNingHX)

Changes

Add a parse-time check so that LLParser treats the type: field of
DISubprogram as required and non-null. Attempting to assemble IR with
a missing or null type: now produces a clear parse-time error
("missing required field 'type'" or "'type' cannot be null") rather
than relying solely on the verifier warning added in #194556.

Update existing hand-written LLVM IR tests to supply a minimal valid
DISubroutineType where they are not intentionally testing malformed
debug info.

Scope. This patch covers the LLParser path only. Two entry points
are intentionally deferred:

  • MetadataLoader: pre-LLVM-5 bitcode legitimately stores null
    DISubprogram.type; auto-upgrading that field requires more careful
    backward-compatibility handling (see llvm/test/Bitcode/dityperefs-3.8.ll).
  • BitcodeWriter: IR written to bitcode has already passed the
    verifier, which guarantees a non-null type; no additional check is
    needed in the writer.

Follow-up to #194556.


Patch is 75.43 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/196299.diff

88 Files Affected:

  • (modified) llvm/lib/AsmParser/LLParser.cpp (+1-1)
  • (modified) llvm/test/Analysis/CostModel/X86/free-intrinsics.ll (+3-1)
  • (modified) llvm/test/Analysis/CostModel/free-intrinsics-datalayout.ll (+3-1)
  • (modified) llvm/test/Analysis/CostModel/free-intrinsics-no_info.ll (+3-1)
  • (added) llvm/test/Assembler/disubprogram-type-required.ll (+29)
  • (modified) llvm/test/Assembler/drop-debug-info-nonzero-alloca.ll (+3-1)
  • (modified) llvm/test/Assembler/invalid-diflag-bad.ll (+3-1)
  • (modified) llvm/test/Assembler/invalid-disubprogram-uniqued-definition.ll (+3-1)
  • (modified) llvm/test/CodeGen/AArch64/GlobalISel/fconstant-dbg-loc.ll (+3-1)
  • (modified) llvm/test/CodeGen/AArch64/sdag-no-typesize-warnings-regandsizes.ll (+3-1)
  • (modified) llvm/test/CodeGen/AArch64/selectiondag-order.ll (+3-1)
  • (modified) llvm/test/CodeGen/AMDGPU/simplify-libcalls2.ll (+3-1)
  • (modified) llvm/test/CodeGen/ARM/2009-10-16-Scope.ll (+3-1)
  • (modified) llvm/test/CodeGen/ARM/analyze-branch-bkpt.ll (+5-3)
  • (modified) llvm/test/CodeGen/Generic/dbg_value.ll (+3-1)
  • (modified) llvm/test/CodeGen/MIR/X86/fixed-stack-di.mir (+3-1)
  • (modified) llvm/test/CodeGen/MIR/X86/invalid-metadata-node-type.mir (+3-1)
  • (modified) llvm/test/CodeGen/RISCV/rvv/get-vlen-debugloc.mir (+3-1)
  • (modified) llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/2009-10-16-Scope.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/AMX/amx-ldtilecfg-insert.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/GlobalISel/regbankselect-dbg-value-physreg-crash.mir (+3-1)
  • (modified) llvm/test/CodeGen/X86/StackColoring-dbg.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/addrsig.ll (+4-2)
  • (modified) llvm/test/CodeGen/X86/dbg-changes-codegen.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/frame-lowering-debug-intrinsic-2.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/frame-lowering-debug-intrinsic.ll (+4-2)
  • (modified) llvm/test/CodeGen/X86/lrshrink.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/machine-trace-metrics-crash.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/opt_phis.mir (+3-1)
  • (modified) llvm/test/CodeGen/X86/pr149841.ll (+3-2)
  • (modified) llvm/test/CodeGen/X86/pr57673.mir (+3-1)
  • (modified) llvm/test/CodeGen/X86/selectiondag-dbgvalue-null-crash.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/selectiondag-order.ll (+3-1)
  • (modified) llvm/test/DebugInfo/AArch64/abstract-sp-unit.ll (+2-2)
  • (modified) llvm/test/DebugInfo/AArch64/merge-locations-legalizer.mir (+3-1)
  • (modified) llvm/test/DebugInfo/Generic/split-dwarf-local-import2.ll (+3-3)
  • (modified) llvm/test/DebugInfo/MIR/X86/regcoalescing-clears-dead-dbgvals.mir (+3-1)
  • (modified) llvm/test/DebugInfo/X86/empty-struct-no-crash.ll (+4-2)
  • (modified) llvm/test/LTO/X86/Inputs/strip-debug-info-bar.ll (+3-2)
  • (modified) llvm/test/LTO/X86/Inputs/type-mapping-bug2.ll (+3-1)
  • (modified) llvm/test/LTO/X86/Inputs/type-mapping-bug3.ll (+3-1)
  • (modified) llvm/test/LTO/X86/pr38046.ll (+3-1)
  • (modified) llvm/test/LTO/X86/type-mapping-bug2.ll (+3-2)
  • (modified) llvm/test/Linker/2009-09-03-mdnode.ll (+3-1)
  • (modified) llvm/test/Linker/2009-09-03-mdnode2.ll (+3-1)
  • (modified) llvm/test/Linker/odr.ll (+3-1)
  • (modified) llvm/test/Other/dropped-var-stats.ll (+5-3)
  • (modified) llvm/test/Transforms/AddDiscriminators/dbg-declare-discriminator.ll (+5-3)
  • (modified) llvm/test/Transforms/GlobalDCE/global_ctors.ll (+3-1)
  • (modified) llvm/test/Transforms/Inline/ignore-debug-info.ll (+3-1)
  • (modified) llvm/test/Transforms/InstCombine/debuginfo-scalable-typesize.ll (+3-1)
  • (modified) llvm/test/Transforms/LoopStrengthReduce/pr12018.ll (+3-1)
  • (modified) llvm/test/Transforms/ObjCARC/basic.ll (+3-1)
  • (modified) llvm/test/Transforms/SampleProfile/nodebug.ll (+3-1)
  • (modified) llvm/test/Transforms/SampleProfile/summary.ll (+4-2)
  • (modified) llvm/test/Transforms/SimplifyCFG/X86/sink-common-code.ll (+3-1)
  • (modified) llvm/test/Transforms/SimplifyCFG/preserve-llvm-loop-metadata.ll (+3-1)
  • (modified) llvm/test/Transforms/Util/store-first-op.ll (+3-1)
  • (modified) llvm/test/Transforms/WholeProgramDevirt/devirt-metadata.ll (+6-5)
  • (modified) llvm/test/Verifier/DISubprogram-type.ll (+12-27)
  • (modified) llvm/test/Verifier/RemoveDI/blockbyref.ll (+3-1)
  • (modified) llvm/test/Verifier/RemoveDI/fnarg-debuginfo.ll (+3-1)
  • (modified) llvm/test/Verifier/RemoveDI/llvm.dbg.declare-address.ll (+3-1)
  • (modified) llvm/test/Verifier/RemoveDI/llvm.dbg.declare-expression.ll (+3-1)
  • (modified) llvm/test/Verifier/RemoveDI/llvm.dbg.declare-variable.ll (+3-1)
  • (modified) llvm/test/Verifier/RemoveDI/llvm.dbg.intrinsic-dbg-attachment.ll (+4-2)
  • (modified) llvm/test/Verifier/RemoveDI/llvm.dbg.value-expression.ll (+3-1)
  • (modified) llvm/test/Verifier/RemoveDI/llvm.dbg.value-value.ll (+3-1)
  • (modified) llvm/test/Verifier/RemoveDI/llvm.dbg.value-variable.ll (+3-1)
  • (modified) llvm/test/Verifier/blockbyref.ll (+3-1)
  • (modified) llvm/test/Verifier/dbg-difile-crash.ll (+3-1)
  • (modified) llvm/test/Verifier/dbg-invalid-retaintypes.ll (+3-1)
  • (modified) llvm/test/Verifier/dbg-line-without-file.ll (+3-1)
  • (modified) llvm/test/Verifier/dbg.ll (+3-1)
  • (modified) llvm/test/Verifier/fnarg-debuginfo.ll (+3-1)
  • (modified) llvm/test/Verifier/func-dbg.ll (+4-2)
  • (modified) llvm/test/Verifier/llvm.dbg.declare-address.ll (+3-1)
  • (modified) llvm/test/Verifier/llvm.dbg.declare-expression.ll (+3-1)
  • (modified) llvm/test/Verifier/llvm.dbg.declare-variable.ll (+3-1)
  • (modified) llvm/test/Verifier/llvm.dbg.intrinsic-dbg-attachment.ll (+4-2)
  • (modified) llvm/test/Verifier/llvm.dbg.value-expression.ll (+3-1)
  • (modified) llvm/test/Verifier/llvm.dbg.value-value.ll (+3-1)
  • (modified) llvm/test/Verifier/llvm.dbg.value-variable.ll (+3-1)
  • (modified) llvm/test/Verifier/llvm.loop.ll (+4-2)
  • (modified) llvm/test/Verifier/local-import-in-cu.ll (+3-1)
  • (modified) llvm/test/Verifier/metadata-function-dbg.ll (+4-2)
  • (modified) llvm/test/Verifier/pr34325.ll (+3-1)
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...
[truncated]

@llvmorg-github-actions
Copy link
Copy Markdown

@llvm/pr-subscribers-backend-x86

Author: Jiang Ning (JiangNingHX)

Changes

Add a parse-time check so that LLParser treats the type: field of
DISubprogram as required and non-null. Attempting to assemble IR with
a missing or null type: now produces a clear parse-time error
("missing required field 'type'" or "'type' cannot be null") rather
than relying solely on the verifier warning added in #194556.

Update existing hand-written LLVM IR tests to supply a minimal valid
DISubroutineType where they are not intentionally testing malformed
debug info.

Scope. This patch covers the LLParser path only. Two entry points
are intentionally deferred:

  • MetadataLoader: pre-LLVM-5 bitcode legitimately stores null
    DISubprogram.type; auto-upgrading that field requires more careful
    backward-compatibility handling (see llvm/test/Bitcode/dityperefs-3.8.ll).
  • BitcodeWriter: IR written to bitcode has already passed the
    verifier, which guarantees a non-null type; no additional check is
    needed in the writer.

Follow-up to #194556.


Patch is 75.43 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/196299.diff

88 Files Affected:

  • (modified) llvm/lib/AsmParser/LLParser.cpp (+1-1)
  • (modified) llvm/test/Analysis/CostModel/X86/free-intrinsics.ll (+3-1)
  • (modified) llvm/test/Analysis/CostModel/free-intrinsics-datalayout.ll (+3-1)
  • (modified) llvm/test/Analysis/CostModel/free-intrinsics-no_info.ll (+3-1)
  • (added) llvm/test/Assembler/disubprogram-type-required.ll (+29)
  • (modified) llvm/test/Assembler/drop-debug-info-nonzero-alloca.ll (+3-1)
  • (modified) llvm/test/Assembler/invalid-diflag-bad.ll (+3-1)
  • (modified) llvm/test/Assembler/invalid-disubprogram-uniqued-definition.ll (+3-1)
  • (modified) llvm/test/CodeGen/AArch64/GlobalISel/fconstant-dbg-loc.ll (+3-1)
  • (modified) llvm/test/CodeGen/AArch64/sdag-no-typesize-warnings-regandsizes.ll (+3-1)
  • (modified) llvm/test/CodeGen/AArch64/selectiondag-order.ll (+3-1)
  • (modified) llvm/test/CodeGen/AMDGPU/simplify-libcalls2.ll (+3-1)
  • (modified) llvm/test/CodeGen/ARM/2009-10-16-Scope.ll (+3-1)
  • (modified) llvm/test/CodeGen/ARM/analyze-branch-bkpt.ll (+5-3)
  • (modified) llvm/test/CodeGen/Generic/dbg_value.ll (+3-1)
  • (modified) llvm/test/CodeGen/MIR/X86/fixed-stack-di.mir (+3-1)
  • (modified) llvm/test/CodeGen/MIR/X86/invalid-metadata-node-type.mir (+3-1)
  • (modified) llvm/test/CodeGen/RISCV/rvv/get-vlen-debugloc.mir (+3-1)
  • (modified) llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/2009-10-16-Scope.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/AMX/amx-ldtilecfg-insert.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/GlobalISel/regbankselect-dbg-value-physreg-crash.mir (+3-1)
  • (modified) llvm/test/CodeGen/X86/StackColoring-dbg.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/addrsig.ll (+4-2)
  • (modified) llvm/test/CodeGen/X86/dbg-changes-codegen.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/frame-lowering-debug-intrinsic-2.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/frame-lowering-debug-intrinsic.ll (+4-2)
  • (modified) llvm/test/CodeGen/X86/lrshrink.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/machine-trace-metrics-crash.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/opt_phis.mir (+3-1)
  • (modified) llvm/test/CodeGen/X86/pr149841.ll (+3-2)
  • (modified) llvm/test/CodeGen/X86/pr57673.mir (+3-1)
  • (modified) llvm/test/CodeGen/X86/selectiondag-dbgvalue-null-crash.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/selectiondag-order.ll (+3-1)
  • (modified) llvm/test/DebugInfo/AArch64/abstract-sp-unit.ll (+2-2)
  • (modified) llvm/test/DebugInfo/AArch64/merge-locations-legalizer.mir (+3-1)
  • (modified) llvm/test/DebugInfo/Generic/split-dwarf-local-import2.ll (+3-3)
  • (modified) llvm/test/DebugInfo/MIR/X86/regcoalescing-clears-dead-dbgvals.mir (+3-1)
  • (modified) llvm/test/DebugInfo/X86/empty-struct-no-crash.ll (+4-2)
  • (modified) llvm/test/LTO/X86/Inputs/strip-debug-info-bar.ll (+3-2)
  • (modified) llvm/test/LTO/X86/Inputs/type-mapping-bug2.ll (+3-1)
  • (modified) llvm/test/LTO/X86/Inputs/type-mapping-bug3.ll (+3-1)
  • (modified) llvm/test/LTO/X86/pr38046.ll (+3-1)
  • (modified) llvm/test/LTO/X86/type-mapping-bug2.ll (+3-2)
  • (modified) llvm/test/Linker/2009-09-03-mdnode.ll (+3-1)
  • (modified) llvm/test/Linker/2009-09-03-mdnode2.ll (+3-1)
  • (modified) llvm/test/Linker/odr.ll (+3-1)
  • (modified) llvm/test/Other/dropped-var-stats.ll (+5-3)
  • (modified) llvm/test/Transforms/AddDiscriminators/dbg-declare-discriminator.ll (+5-3)
  • (modified) llvm/test/Transforms/GlobalDCE/global_ctors.ll (+3-1)
  • (modified) llvm/test/Transforms/Inline/ignore-debug-info.ll (+3-1)
  • (modified) llvm/test/Transforms/InstCombine/debuginfo-scalable-typesize.ll (+3-1)
  • (modified) llvm/test/Transforms/LoopStrengthReduce/pr12018.ll (+3-1)
  • (modified) llvm/test/Transforms/ObjCARC/basic.ll (+3-1)
  • (modified) llvm/test/Transforms/SampleProfile/nodebug.ll (+3-1)
  • (modified) llvm/test/Transforms/SampleProfile/summary.ll (+4-2)
  • (modified) llvm/test/Transforms/SimplifyCFG/X86/sink-common-code.ll (+3-1)
  • (modified) llvm/test/Transforms/SimplifyCFG/preserve-llvm-loop-metadata.ll (+3-1)
  • (modified) llvm/test/Transforms/Util/store-first-op.ll (+3-1)
  • (modified) llvm/test/Transforms/WholeProgramDevirt/devirt-metadata.ll (+6-5)
  • (modified) llvm/test/Verifier/DISubprogram-type.ll (+12-27)
  • (modified) llvm/test/Verifier/RemoveDI/blockbyref.ll (+3-1)
  • (modified) llvm/test/Verifier/RemoveDI/fnarg-debuginfo.ll (+3-1)
  • (modified) llvm/test/Verifier/RemoveDI/llvm.dbg.declare-address.ll (+3-1)
  • (modified) llvm/test/Verifier/RemoveDI/llvm.dbg.declare-expression.ll (+3-1)
  • (modified) llvm/test/Verifier/RemoveDI/llvm.dbg.declare-variable.ll (+3-1)
  • (modified) llvm/test/Verifier/RemoveDI/llvm.dbg.intrinsic-dbg-attachment.ll (+4-2)
  • (modified) llvm/test/Verifier/RemoveDI/llvm.dbg.value-expression.ll (+3-1)
  • (modified) llvm/test/Verifier/RemoveDI/llvm.dbg.value-value.ll (+3-1)
  • (modified) llvm/test/Verifier/RemoveDI/llvm.dbg.value-variable.ll (+3-1)
  • (modified) llvm/test/Verifier/blockbyref.ll (+3-1)
  • (modified) llvm/test/Verifier/dbg-difile-crash.ll (+3-1)
  • (modified) llvm/test/Verifier/dbg-invalid-retaintypes.ll (+3-1)
  • (modified) llvm/test/Verifier/dbg-line-without-file.ll (+3-1)
  • (modified) llvm/test/Verifier/dbg.ll (+3-1)
  • (modified) llvm/test/Verifier/fnarg-debuginfo.ll (+3-1)
  • (modified) llvm/test/Verifier/func-dbg.ll (+4-2)
  • (modified) llvm/test/Verifier/llvm.dbg.declare-address.ll (+3-1)
  • (modified) llvm/test/Verifier/llvm.dbg.declare-expression.ll (+3-1)
  • (modified) llvm/test/Verifier/llvm.dbg.declare-variable.ll (+3-1)
  • (modified) llvm/test/Verifier/llvm.dbg.intrinsic-dbg-attachment.ll (+4-2)
  • (modified) llvm/test/Verifier/llvm.dbg.value-expression.ll (+3-1)
  • (modified) llvm/test/Verifier/llvm.dbg.value-value.ll (+3-1)
  • (modified) llvm/test/Verifier/llvm.dbg.value-variable.ll (+3-1)
  • (modified) llvm/test/Verifier/llvm.loop.ll (+4-2)
  • (modified) llvm/test/Verifier/local-import-in-cu.ll (+3-1)
  • (modified) llvm/test/Verifier/metadata-function-dbg.ll (+4-2)
  • (modified) llvm/test/Verifier/pr34325.ll (+3-1)
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...
[truncated]

@llvmorg-github-actions
Copy link
Copy Markdown

@llvm/pr-subscribers-lto

Author: Jiang Ning (JiangNingHX)

Changes

Add a parse-time check so that LLParser treats the type: field of
DISubprogram as required and non-null. Attempting to assemble IR with
a missing or null type: now produces a clear parse-time error
("missing required field 'type'" or "'type' cannot be null") rather
than relying solely on the verifier warning added in #194556.

Update existing hand-written LLVM IR tests to supply a minimal valid
DISubroutineType where they are not intentionally testing malformed
debug info.

Scope. This patch covers the LLParser path only. Two entry points
are intentionally deferred:

  • MetadataLoader: pre-LLVM-5 bitcode legitimately stores null
    DISubprogram.type; auto-upgrading that field requires more careful
    backward-compatibility handling (see llvm/test/Bitcode/dityperefs-3.8.ll).
  • BitcodeWriter: IR written to bitcode has already passed the
    verifier, which guarantees a non-null type; no additional check is
    needed in the writer.

Follow-up to #194556.


Patch is 75.43 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/196299.diff

88 Files Affected:

  • (modified) llvm/lib/AsmParser/LLParser.cpp (+1-1)
  • (modified) llvm/test/Analysis/CostModel/X86/free-intrinsics.ll (+3-1)
  • (modified) llvm/test/Analysis/CostModel/free-intrinsics-datalayout.ll (+3-1)
  • (modified) llvm/test/Analysis/CostModel/free-intrinsics-no_info.ll (+3-1)
  • (added) llvm/test/Assembler/disubprogram-type-required.ll (+29)
  • (modified) llvm/test/Assembler/drop-debug-info-nonzero-alloca.ll (+3-1)
  • (modified) llvm/test/Assembler/invalid-diflag-bad.ll (+3-1)
  • (modified) llvm/test/Assembler/invalid-disubprogram-uniqued-definition.ll (+3-1)
  • (modified) llvm/test/CodeGen/AArch64/GlobalISel/fconstant-dbg-loc.ll (+3-1)
  • (modified) llvm/test/CodeGen/AArch64/sdag-no-typesize-warnings-regandsizes.ll (+3-1)
  • (modified) llvm/test/CodeGen/AArch64/selectiondag-order.ll (+3-1)
  • (modified) llvm/test/CodeGen/AMDGPU/simplify-libcalls2.ll (+3-1)
  • (modified) llvm/test/CodeGen/ARM/2009-10-16-Scope.ll (+3-1)
  • (modified) llvm/test/CodeGen/ARM/analyze-branch-bkpt.ll (+5-3)
  • (modified) llvm/test/CodeGen/Generic/dbg_value.ll (+3-1)
  • (modified) llvm/test/CodeGen/MIR/X86/fixed-stack-di.mir (+3-1)
  • (modified) llvm/test/CodeGen/MIR/X86/invalid-metadata-node-type.mir (+3-1)
  • (modified) llvm/test/CodeGen/RISCV/rvv/get-vlen-debugloc.mir (+3-1)
  • (modified) llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/2009-10-16-Scope.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/AMX/amx-ldtilecfg-insert.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/GlobalISel/regbankselect-dbg-value-physreg-crash.mir (+3-1)
  • (modified) llvm/test/CodeGen/X86/StackColoring-dbg.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/addrsig.ll (+4-2)
  • (modified) llvm/test/CodeGen/X86/dbg-changes-codegen.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/frame-lowering-debug-intrinsic-2.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/frame-lowering-debug-intrinsic.ll (+4-2)
  • (modified) llvm/test/CodeGen/X86/lrshrink.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/machine-trace-metrics-crash.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/opt_phis.mir (+3-1)
  • (modified) llvm/test/CodeGen/X86/pr149841.ll (+3-2)
  • (modified) llvm/test/CodeGen/X86/pr57673.mir (+3-1)
  • (modified) llvm/test/CodeGen/X86/selectiondag-dbgvalue-null-crash.ll (+3-1)
  • (modified) llvm/test/CodeGen/X86/selectiondag-order.ll (+3-1)
  • (modified) llvm/test/DebugInfo/AArch64/abstract-sp-unit.ll (+2-2)
  • (modified) llvm/test/DebugInfo/AArch64/merge-locations-legalizer.mir (+3-1)
  • (modified) llvm/test/DebugInfo/Generic/split-dwarf-local-import2.ll (+3-3)
  • (modified) llvm/test/DebugInfo/MIR/X86/regcoalescing-clears-dead-dbgvals.mir (+3-1)
  • (modified) llvm/test/DebugInfo/X86/empty-struct-no-crash.ll (+4-2)
  • (modified) llvm/test/LTO/X86/Inputs/strip-debug-info-bar.ll (+3-2)
  • (modified) llvm/test/LTO/X86/Inputs/type-mapping-bug2.ll (+3-1)
  • (modified) llvm/test/LTO/X86/Inputs/type-mapping-bug3.ll (+3-1)
  • (modified) llvm/test/LTO/X86/pr38046.ll (+3-1)
  • (modified) llvm/test/LTO/X86/type-mapping-bug2.ll (+3-2)
  • (modified) llvm/test/Linker/2009-09-03-mdnode.ll (+3-1)
  • (modified) llvm/test/Linker/2009-09-03-mdnode2.ll (+3-1)
  • (modified) llvm/test/Linker/odr.ll (+3-1)
  • (modified) llvm/test/Other/dropped-var-stats.ll (+5-3)
  • (modified) llvm/test/Transforms/AddDiscriminators/dbg-declare-discriminator.ll (+5-3)
  • (modified) llvm/test/Transforms/GlobalDCE/global_ctors.ll (+3-1)
  • (modified) llvm/test/Transforms/Inline/ignore-debug-info.ll (+3-1)
  • (modified) llvm/test/Transforms/InstCombine/debuginfo-scalable-typesize.ll (+3-1)
  • (modified) llvm/test/Transforms/LoopStrengthReduce/pr12018.ll (+3-1)
  • (modified) llvm/test/Transforms/ObjCARC/basic.ll (+3-1)
  • (modified) llvm/test/Transforms/SampleProfile/nodebug.ll (+3-1)
  • (modified) llvm/test/Transforms/SampleProfile/summary.ll (+4-2)
  • (modified) llvm/test/Transforms/SimplifyCFG/X86/sink-common-code.ll (+3-1)
  • (modified) llvm/test/Transforms/SimplifyCFG/preserve-llvm-loop-metadata.ll (+3-1)
  • (modified) llvm/test/Transforms/Util/store-first-op.ll (+3-1)
  • (modified) llvm/test/Transforms/WholeProgramDevirt/devirt-metadata.ll (+6-5)
  • (modified) llvm/test/Verifier/DISubprogram-type.ll (+12-27)
  • (modified) llvm/test/Verifier/RemoveDI/blockbyref.ll (+3-1)
  • (modified) llvm/test/Verifier/RemoveDI/fnarg-debuginfo.ll (+3-1)
  • (modified) llvm/test/Verifier/RemoveDI/llvm.dbg.declare-address.ll (+3-1)
  • (modified) llvm/test/Verifier/RemoveDI/llvm.dbg.declare-expression.ll (+3-1)
  • (modified) llvm/test/Verifier/RemoveDI/llvm.dbg.declare-variable.ll (+3-1)
  • (modified) llvm/test/Verifier/RemoveDI/llvm.dbg.intrinsic-dbg-attachment.ll (+4-2)
  • (modified) llvm/test/Verifier/RemoveDI/llvm.dbg.value-expression.ll (+3-1)
  • (modified) llvm/test/Verifier/RemoveDI/llvm.dbg.value-value.ll (+3-1)
  • (modified) llvm/test/Verifier/RemoveDI/llvm.dbg.value-variable.ll (+3-1)
  • (modified) llvm/test/Verifier/blockbyref.ll (+3-1)
  • (modified) llvm/test/Verifier/dbg-difile-crash.ll (+3-1)
  • (modified) llvm/test/Verifier/dbg-invalid-retaintypes.ll (+3-1)
  • (modified) llvm/test/Verifier/dbg-line-without-file.ll (+3-1)
  • (modified) llvm/test/Verifier/dbg.ll (+3-1)
  • (modified) llvm/test/Verifier/fnarg-debuginfo.ll (+3-1)
  • (modified) llvm/test/Verifier/func-dbg.ll (+4-2)
  • (modified) llvm/test/Verifier/llvm.dbg.declare-address.ll (+3-1)
  • (modified) llvm/test/Verifier/llvm.dbg.declare-expression.ll (+3-1)
  • (modified) llvm/test/Verifier/llvm.dbg.declare-variable.ll (+3-1)
  • (modified) llvm/test/Verifier/llvm.dbg.intrinsic-dbg-attachment.ll (+4-2)
  • (modified) llvm/test/Verifier/llvm.dbg.value-expression.ll (+3-1)
  • (modified) llvm/test/Verifier/llvm.dbg.value-value.ll (+3-1)
  • (modified) llvm/test/Verifier/llvm.dbg.value-variable.ll (+3-1)
  • (modified) llvm/test/Verifier/llvm.loop.ll (+4-2)
  • (modified) llvm/test/Verifier/local-import-in-cu.ll (+3-1)
  • (modified) llvm/test/Verifier/metadata-function-dbg.ll (+4-2)
  • (modified) llvm/test/Verifier/pr34325.ll (+3-1)
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...
[truncated]

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

🪟 Windows x64 Test Results

  • 134459 tests passed
  • 3253 tests skipped

✅ The build succeeded and all tests passed.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

🐧 Linux x64 Test Results

  • 195056 tests passed
  • 5187 tests skipped

✅ The build succeeded and all tests passed.

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 llvm#194556.

Update existing tests to supply a minimal valid type field where they
are not intentionally testing malformed debug info.
@JiangNingHX JiangNingHX force-pushed the disubprogram-type-llparser branch from 0a3d240 to 211c919 Compare May 8, 2026 02:38
Copy link
Copy Markdown
Member

@jmorse jmorse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for driving this through!

@JiangNingHX
Copy link
Copy Markdown
Contributor Author

Thanks for the review, @jmorse! The pre-merge checks are green now.

I don't have commit access yet, so could you or another maintainer help land this when convenient?

@Michael137
Copy link
Copy Markdown
Member

One comment regarding the description:

BitcodeWriter: IR written to bitcode has already passed the
verifier, which guarantees a non-null type; no additional check is
needed in the writer.

The writer currently does:

  Record.push_back(VE.getMetadataOrNullID(N->getType()));

We'll want to update this to unconditionally getType for consistency with the updated grammar.

But happy to keep that as a follow-up

@Michael137 Michael137 merged commit 6d42b9a into llvm:main May 13, 2026
10 checks passed
lialan pushed a commit to lialan/llvm-project that referenced this pull request May 13, 2026
…96299)

Add a parse-time check so that LLParser treats the `type:` field of
`DISubprogram` as required and non-null. Attempting to assemble IR with
  a missing or null `type:` now produces a clear parse-time error
("missing required field 'type'" or "'type' cannot be null") rather
than relying solely on the verifier warning added in llvm#194556.
Update existing hand-written LLVM IR tests to supply a minimal valid
`DISubroutineType` where they are not intentionally testing malformed
debug info.
**Scope.** This patch covers the LLParser path only. Two entry points
are intentionally deferred:
- *MetadataLoader*: pre-LLVM-5 bitcode legitimately stores null
    `DISubprogram.type`; auto-upgrading that field requires more careful
backward-compatibility handling (see
`llvm/test/Bitcode/dityperefs-3.8.ll`).
- *BitcodeWriter*: IR written to bitcode has already passed the
verifier, which guarantees a non-null type; no additional check is
needed in the writer.
  Follow-up to llvm#194556.
@JiangNingHX JiangNingHX deleted the disubprogram-type-llparser branch May 14, 2026 02:22
EuphoricThinking pushed a commit to EuphoricThinking/llvm-project that referenced this pull request May 14, 2026
…96299)

Add a parse-time check so that LLParser treats the `type:` field of
`DISubprogram` as required and non-null. Attempting to assemble IR with
  a missing or null `type:` now produces a clear parse-time error
("missing required field 'type'" or "'type' cannot be null") rather
than relying solely on the verifier warning added in llvm#194556.
Update existing hand-written LLVM IR tests to supply a minimal valid
`DISubroutineType` where they are not intentionally testing malformed
debug info.
**Scope.** This patch covers the LLParser path only. Two entry points
are intentionally deferred:
- *MetadataLoader*: pre-LLVM-5 bitcode legitimately stores null
    `DISubprogram.type`; auto-upgrading that field requires more careful
backward-compatibility handling (see
`llvm/test/Bitcode/dityperefs-3.8.ll`).
- *BitcodeWriter*: IR written to bitcode has already passed the
verifier, which guarantees a non-null type; no additional check is
needed in the writer.
  Follow-up to llvm#194556.
pedroMVicente pushed a commit to pedroMVicente/llvm-project that referenced this pull request May 19, 2026
…96299)

Add a parse-time check so that LLParser treats the `type:` field of
`DISubprogram` as required and non-null. Attempting to assemble IR with
  a missing or null `type:` now produces a clear parse-time error
("missing required field 'type'" or "'type' cannot be null") rather
than relying solely on the verifier warning added in llvm#194556.
Update existing hand-written LLVM IR tests to supply a minimal valid
`DISubroutineType` where they are not intentionally testing malformed
debug info.
**Scope.** This patch covers the LLParser path only. Two entry points
are intentionally deferred:
- *MetadataLoader*: pre-LLVM-5 bitcode legitimately stores null
    `DISubprogram.type`; auto-upgrading that field requires more careful
backward-compatibility handling (see
`llvm/test/Bitcode/dityperefs-3.8.ll`).
- *BitcodeWriter*: IR written to bitcode has already passed the
verifier, which guarantees a non-null type; no additional check is
needed in the writer.
  Follow-up to llvm#194556.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend:AArch64 backend:AMDGPU backend:ARM backend:RISC-V backend:WebAssembly backend:X86 debuginfo llvm:analysis Includes value tracking, cost tables and constant folding llvm:globalisel llvm:instcombine Covers the InstCombine, InstSimplify and AggressiveInstCombine passes llvm:transforms LTO Link time optimization (regular/full LTO or ThinLTO) mlir:llvm mlir PGO Profile Guided Optimizations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants