Verifier: Add check for DICompositeType elements being null

Came up recently with some nodebug case on codeview, that caused a null
entry in elements and crashed LLVM.

Original clang fix to avoid generating IR like this: 504dd57767
This commit is contained in:
David Blaikie
2025-01-17 19:16:32 +00:00
parent 1c3c65590d
commit 2dc5682dac
2 changed files with 8 additions and 0 deletions

View File

@@ -1319,6 +1319,8 @@ void Verifier::visitDICompositeType(const DICompositeType &N) {
unsigned DIBlockByRefStruct = 1 << 4;
CheckDI((N.getFlags() & DIBlockByRefStruct) == 0,
"DIBlockByRefStruct on DICompositeType is no longer supported", &N);
CheckDI(llvm::all_of(N.getElements(), [](const DINode *N) { return N; }),
"DISubprogram contains null entry in `elements` field", &N);
if (N.isVector()) {
const DINodeArray Elements = N.getElements();

View File

@@ -0,0 +1,6 @@
; RUN: not opt -S < %s 2>&1 | FileCheck %s
!named = !{!0}
; CHECK: DISubprogram contains null entry in `elements` field
!0 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t1", elements: !1)
!1 = !{null}