[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 04:27:19 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:
yeah that's a fair point, I agree the comment was misleading. I'll update it to remove that comment, claim since, as you noted, Clang always emits a `DISubroutineType` even with `-gline-tables-only`.
I did some investigation on this honestly, I tested both Clang and rustc with `-gline-tables-only` / `-g`, and neither ever produces a typeless `DISubprogram`. I also tried running `llvm-reduce` to see if it would strip the type: operand during reduction, but it doesn't (as long as what I tested)
but yeah, whether something actually regressed for a real user, we'd need the original reporter to clarify.
That said, the type field is declared OPTIONAL in the parser and the verifier accepts it, so this is valid IR even if no in-tree frontend currently produces it. I think a defensive guard still makes sense here. But let's wait for the actual reproducer.
https://github.com/llvm/llvm-project/pull/184299
More information about the llvm-commits
mailing list