@@ -740,36 +740,25 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) {
740740 " Global is external, but doesn't have external or weak linkage!" , &GV);
741741
742742 if (const GlobalObject *GO = dyn_cast<GlobalObject>(&GV)) {
743- if (GO->hasMetadata (LLVMContext::MD_associated)) {
744- SmallVector<MDNode *, 1 > MDs;
745- GO->getMetadata (LLVMContext::MD_associated, MDs);
746-
747- if (TT.isOSBinFormatELF ())
748- Check (MDs.size () == 1 , " only a single associated metadata is supported" ,
749- &GV);
750-
751- for (const MDNode *Associated : MDs) {
752- Check (Associated->getNumOperands () == 1 ,
753- " associated metadata must have one operand" , &GV, Associated);
754- const Metadata *Op = Associated->getOperand (0 ).get ();
755- Check (Op, " associated metadata must have a global value" , GO,
743+ if (const MDNode *Associated =
744+ GO->getMetadata (LLVMContext::MD_associated)) {
745+ Check (Associated->getNumOperands () == 1 ,
746+ " associated metadata must have one operand" , &GV, Associated);
747+ const Metadata *Op = Associated->getOperand (0 ).get ();
748+ Check (Op, " associated metadata must have a global value" , GO, Associated);
749+
750+ const auto *VM = dyn_cast_or_null<ValueAsMetadata>(Op);
751+ Check (VM, " associated metadata must be ValueAsMetadata" , GO, Associated);
752+ if (VM) {
753+ Check (isa<PointerType>(VM->getValue ()->getType ()),
754+ " associated value must be pointer typed" , GV, Associated);
755+
756+ const Value *Stripped = VM->getValue ()->stripPointerCastsAndAliases ();
757+ Check (isa<GlobalObject>(Stripped) || isa<Constant>(Stripped),
758+ " associated metadata must point to a GlobalObject" , GO, Stripped);
759+ Check (Stripped != GO,
760+ " global values should not associate to themselves" , GO,
756761 Associated);
757-
758- const auto *VM = dyn_cast_or_null<ValueAsMetadata>(Op);
759- Check (VM, " associated metadata must be ValueAsMetadata" , GO,
760- Associated);
761- if (VM) {
762- Check (isa<PointerType>(VM->getValue ()->getType ()),
763- " associated value must be pointer typed" , GV, Associated);
764-
765- const Value *Stripped = VM->getValue ()->stripPointerCastsAndAliases ();
766- Check (isa<GlobalObject>(Stripped) || isa<Constant>(Stripped),
767- " associated metadata must point to a GlobalObject" , GO,
768- Stripped);
769- Check (Stripped != GO,
770- " global values should not associate to themselves" , GO,
771- Associated);
772- }
773762 }
774763 }
775764
@@ -780,6 +769,30 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) {
780769 DL.getIntPtrType (GO->getType ()),
781770 RangeLikeMetadataKind::AbsoluteSymbol);
782771 }
772+
773+ if (GO->hasMetadata (LLVMContext::MD_ref)) {
774+ SmallVector<MDNode *> MDs;
775+ GO->getMetadata (LLVMContext::MD_ref, MDs);
776+ for (const MDNode *MD : MDs) {
777+ Check (MD->getNumOperands () == 1 , " ref metadata must have one operand" ,
778+ &GV, MD);
779+ const Metadata *Op = MD->getOperand (0 ).get ();
780+ Check (Op, " ref metadata must have a global value" , GO, MD);
781+
782+ const auto *VM = dyn_cast_or_null<ValueAsMetadata>(Op);
783+ Check (VM, " ref metadata must be ValueAsMetadata" , GO, MD);
784+ if (VM) {
785+ Check (isa<PointerType>(VM->getValue ()->getType ()),
786+ " ref value must be pointer typed" , GV, MD);
787+
788+ const Value *Stripped = VM->getValue ()->stripPointerCastsAndAliases ();
789+ Check (isa<GlobalObject>(Stripped) || isa<Constant>(Stripped),
790+ " ref metadata must point to a GlobalObject" , GO, Stripped);
791+ Check (Stripped != GO, " values should not reference themselves" , GO,
792+ MD);
793+ }
794+ }
795+ }
783796 }
784797
785798 Check (!GV.hasAppendingLinkage () || isa<GlobalVariable>(GV),
0 commit comments