When parsing function-local metadata, create a function-local MDNode
authorVictor Hernandez <vhernandez@apple.com>
Wed, 6 Jan 2010 17:00:21 +0000 (17:00 +0000)
committerVictor Hernandez <vhernandez@apple.com>
Wed, 6 Jan 2010 17:00:21 +0000 (17:00 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92838 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AsmParser/LLParser.cpp
lib/AsmParser/LLParser.h

index a917d858f5ad6ffa5e419cf939474651ea87d5fc..3ee683f7f67e8853c5d71daf897b036ec692ffd6 100644 (file)
@@ -548,7 +548,7 @@ bool LLParser::ParseStandaloneMetadata() {
       ParseType(Ty, TyLoc) ||
       ParseToken(lltok::exclaim, "Expected '!' here") ||
       ParseToken(lltok::lbrace, "Expected '{' here") ||
-      ParseMDNodeVector(Elts, NULL) ||
+      ParseMDNodeVector(Elts, NULL, NULL) ||
       ParseToken(lltok::rbrace, "expected end of metadata node"))
     return true;
 
@@ -1911,11 +1911,13 @@ bool LLParser::ParseValID(ValID &ID, PerFunctionState *PFS) {
     
     if (EatIfPresent(lltok::lbrace)) {
       SmallVector<Value*, 16> Elts;
-      if (ParseMDNodeVector(Elts, PFS) ||
+      bool isFunctionLocal = false;
+      if (ParseMDNodeVector(Elts, PFS, &isFunctionLocal) ||
           ParseToken(lltok::rbrace, "expected end of metadata node"))
         return true;
 
-      ID.MDNodeVal = MDNode::get(Context, Elts.data(), Elts.size());
+      ID.MDNodeVal = MDNode::get(Context, Elts.data(), Elts.size(),
+                                 isFunctionLocal);
       ID.Kind = ValID::t_MDNode;
       return false;
     }
@@ -2447,7 +2449,8 @@ bool LLParser::ConvertGlobalValIDToValue(const Type *Ty, ValID &ID,
 /// resolved constant, metadata, or function-local value
 bool LLParser::ConvertGlobalOrMetadataValIDToValue(const Type *Ty, ValID &ID,
                                                    Value *&V,
-                                                   PerFunctionState *PFS) {
+                                                   PerFunctionState *PFS,
+                                                   bool *isFunctionLocal) {
   switch (ID.Kind) {
   case ValID::t_MDNode:
     if (!Ty->isMetadataTy())
@@ -2461,9 +2464,10 @@ bool LLParser::ConvertGlobalOrMetadataValIDToValue(const Type *Ty, ValID &ID,
     return false;
   case ValID::t_LocalID:
   case ValID::t_LocalName:
-    if (!PFS)
+    if (!PFS || !isFunctionLocal)
       return Error(ID.Loc, "invalid use of function-local name");
     if (ConvertValIDToValue(Ty, ID, V, *PFS)) return true;
+    *isFunctionLocal = true;
     return false;
   default:
     Constant *C;
@@ -2523,7 +2527,7 @@ bool LLParser::ConvertValIDToValue(const Type *Ty, ValID &ID, Value *&V,
     return false;
   }
   default:
-    return ConvertGlobalOrMetadataValIDToValue(Ty, ID, V, &PFS);
+    return ConvertGlobalOrMetadataValIDToValue(Ty, ID, V, &PFS, NULL);
   }
 
   return V == 0;
@@ -3850,7 +3854,7 @@ int LLParser::ParseInsertValue(Instruction *&Inst, PerFunctionState &PFS) {
 /// Element
 ///   ::= 'null' | TypeAndValue
 bool LLParser::ParseMDNodeVector(SmallVectorImpl<Value*> &Elts,
-                                 PerFunctionState *PFS) {
+                                 PerFunctionState *PFS, bool *isFunctionLocal) {
   do {
     // Null is a special case since it is typeless.
     if (EatIfPresent(lltok::kw_null)) {
@@ -3862,7 +3866,7 @@ bool LLParser::ParseMDNodeVector(SmallVectorImpl<Value*> &Elts,
     PATypeHolder Ty(Type::getVoidTy(Context));
     ValID ID;
     if (ParseType(Ty) || ParseValID(ID, PFS) ||
-        ConvertGlobalOrMetadataValIDToValue(Ty, ID, V, PFS))
+        ConvertGlobalOrMetadataValIDToValue(Ty, ID, V, PFS, isFunctionLocal))
       return true;
     
     Elts.push_back(V);
index 595267b7ff15a9c8b2a9780fc53a91b5458fccce..d532081c5b8ae7a6a81088386204a054964588ff 100644 (file)
@@ -294,11 +294,13 @@ namespace llvm {
     bool ParseValID(ValID &ID, PerFunctionState *PFS = NULL);
     bool ConvertGlobalValIDToValue(const Type *Ty, ValID &ID, Constant *&V);
     bool ConvertGlobalOrMetadataValIDToValue(const Type *Ty, ValID &ID,
-                                             Value *&V, PerFunctionState *PFS);
+                                             Value *&V, PerFunctionState *PFS,
+                                             bool *isFunctionLocal);
     bool ParseGlobalValue(const Type *Ty, Constant *&V);
     bool ParseGlobalTypeAndValue(Constant *&V);
     bool ParseGlobalValueVector(SmallVectorImpl<Constant*> &Elts);
-    bool ParseMDNodeVector(SmallVectorImpl<Value*> &, PerFunctionState *PFS);
+    bool ParseMDNodeVector(SmallVectorImpl<Value*> &, PerFunctionState *PFS,
+                           bool *isFunctionLocal);
 
     // Function Parsing.
     struct ArgInfo {