diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -663,22 +663,29 @@ GO->getMetadata(LLVMContext::MD_associated)) { Check(Associated->getNumOperands() == 1, "associated metadata must have one operand", &GV, Associated); - const Metadata *Op = Associated->getOperand(0).get(); - Check(Op, "associated metadata must have a global value", GO, Associated); - - const auto *VM = dyn_cast_or_null(Op); - Check(VM, "associated metadata must be ValueAsMetadata", GO, Associated); - if (VM) { - Check(isa(VM->getValue()->getType()), - "associated value must be pointer typed", GV, Associated); - - const Value *Stripped = VM->getValue()->stripPointerCastsAndAliases(); - Check(isa(Stripped) || isa(Stripped), - "associated metadata must point to a GlobalObject", GO, Stripped); - Check(Stripped != GO, - "global values should not associate to themselves", GO, + auto CheckAssocOperand = [this, &GV, GO, Associated](const Metadata *Op) { + Check(Op, "associated metadata must have a global value", GO, Associated); - } + + const auto *VM = dyn_cast_or_null(Op); + Check(VM, "associated metadata must be ValueAsMetadata", GO, + Associated); + if (VM) { + Check(isa(VM->getValue()->getType()), + "associated value must be pointer typed", GV, Associated); + + const Value *Stripped = VM->getValue()->stripPointerCastsAndAliases(); + Check(isa(Stripped) || isa(Stripped), + "associated metadata must point to a GlobalObject", GO, + Stripped); + Check(Stripped != GO, + "global values should not associate to themselves", GO, + Associated); + } + }; + + for (unsigned i = 0, e = Associated->getNumOperands(); i != e; ++i) + CheckAssocOperand(Associated->getOperand(i).get()); } } Check(!GV.hasAppendingLinkage() || isa(GV),