IR: Disallow function-local metadata attachments

Metadata attachments to instructions cannot be function-local.

This is part of PR21532.

llvm-svn: 223574
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 93eb490..f44af67 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -62,6 +62,8 @@
             NumberedMetadata[SlotNo] == nullptr)
           return Error(MDList[i].Loc, "use of undefined metadata '!" +
                        Twine(SlotNo) + "'");
+        assert(!NumberedMetadata[SlotNo]->isFunctionLocal() &&
+               "Unexpected function-local metadata");
         Inst->setMetadata(MDList[i].MDKind, NumberedMetadata[SlotNo]);
       }
     }
@@ -1529,6 +1531,8 @@
       if (ParseMetadataListValue(ID, PFS))
         return true;
       assert(ID.Kind == ValID::t_MDNode);
+      if (ID.MDNodeVal->isFunctionLocal())
+        return TokError("unexpected function-local metadata");
       Inst->setMetadata(MDK, ID.MDNodeVal);
     } else {
       unsigned NodeID = 0;