diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index 7b6f7b5aa617..00280dbe5300 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -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(); diff --git a/llvm/test/Verifier/dicompositetype-elements-null.ll b/llvm/test/Verifier/dicompositetype-elements-null.ll new file mode 100644 index 000000000000..c0aca47852ba --- /dev/null +++ b/llvm/test/Verifier/dicompositetype-elements-null.ll @@ -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}