diff options
-rw-r--r-- | llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 6 | ||||
-rw-r--r-- | llvm/test/CodeGen/X86/elf-associated.ll | 5 |
2 files changed, 10 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 34892680ace..1d232c71d82 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -232,7 +232,11 @@ static const MCSymbolELF *getAssociatedSymbol(const GlobalObject *GO, if (!MD) return nullptr; - auto *VM = dyn_cast<ValueAsMetadata>(MD->getOperand(0)); + const MDOperand &Op = MD->getOperand(0); + if (!Op.get()) + return nullptr; + + auto *VM = dyn_cast<ValueAsMetadata>(Op); if (!VM) report_fatal_error("MD_associated operand is not ValueAsMetadata"); diff --git a/llvm/test/CodeGen/X86/elf-associated.ll b/llvm/test/CodeGen/X86/elf-associated.ll index 361cf66cce7..7d58c343702 100644 --- a/llvm/test/CodeGen/X86/elf-associated.ll +++ b/llvm/test/CodeGen/X86/elf-associated.ll @@ -37,3 +37,8 @@ @l = global i32 1, section "ccc", !associated !5 !5 = !{i32* null} ; CHECK-DAG: .section ccc,"aw",@progbits + +; Null metadata. +@m = global i32 1, section "ddd", !associated !6 +!6 = distinct !{null} +; CHECK-DAG: .section ddd,"aw",@progbits |