[llvm] [DebugInfo] Fix segfault in constructSubprogramScopeDIE with null subprogram type (PR #184299)

Shivam Kunwar via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 3 03:55:21 PST 2026


================
@@ -1141,15 +1141,19 @@ DIE &DwarfCompileUnit::constructSubprogramScopeDIE(const DISubprogram *Sub,
   }
 
   // If this is a variadic function, add an unspecified parameter.
-  DITypeArray FnArgs = Sub->getType()->getTypeArray();
-
-  // If we have a single element of null, it is a function that returns void.
-  // If we have more than one elements and the last one is null, it is a
-  // variadic function.
-  if (FnArgs.size() > 1 && !FnArgs[FnArgs.size() - 1] &&
-      !includeMinimalInlineScopes())
-    ScopeDIE.addChild(
-        DIE::get(DIEValueAllocator, dwarf::DW_TAG_unspecified_parameters));
+  // Sub->getType() may be null when using LineTablesOnly emission, since
+  // DISubprograms are not required to have a type in that mode.
----------------
phyBrackets wrote:

The type field of DISubprogram is declared OPTIONAL in the IR parser https://github.com/llvm/llvm-project/blob/ee8259dcca82849735225c8ea1b215ed7fef7648/llvm/lib/AsmParser/LLParser.cpp#L6144 , so getType() returning null is valid by the IR grammar. Additionally, the bitcode reader, C API, and `DIBuilder::createFunction` all accept null type without validation. So, I think the null guard in `constructSubprogramScopeDIE` is warranted

https://github.com/llvm/llvm-project/pull/184299


More information about the llvm-commits mailing list