Compute isFunctionLocal in MDNode ctor or via argument in new function getWhenValsUnresolved().
Document PFS argument to ParseValID() and ConvertGlobalOrMetadataValIDToValue().
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93108 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp
index 9de1ff9..b94aaeb 100644
--- a/lib/AsmParser/LLParser.cpp
+++ b/lib/AsmParser/LLParser.cpp
@@ -548,7 +548,7 @@
ParseType(Ty, TyLoc) ||
ParseToken(lltok::exclaim, "Expected '!' here") ||
ParseToken(lltok::lbrace, "Expected '{' here") ||
- ParseMDNodeVector(Elts, NULL, NULL) ||
+ ParseMDNodeVector(Elts, NULL) ||
ParseToken(lltok::rbrace, "expected end of metadata node"))
return true;
@@ -1884,7 +1884,9 @@
/// ParseValID - Parse an abstract value that doesn't necessarily have a
/// type implied. For example, if we parse "4" we don't know what integer type
/// it has. The value will later be combined with its type and checked for
-/// sanity.
+/// sanity. PFS is used to convert function-local operands of metadata (since
+/// metadata operands are not just parsed here but also converted to values).
+/// PFS can be null when we are not parsing metadata values inside a function.
bool LLParser::ParseValID(ValID &ID, PerFunctionState *PFS) {
ID.Loc = Lex.getLoc();
switch (Lex.getKind()) {
@@ -1911,13 +1913,11 @@
if (EatIfPresent(lltok::lbrace)) {
SmallVector<Value*, 16> Elts;
- bool isFunctionLocal = false;
- if (ParseMDNodeVector(Elts, PFS, &isFunctionLocal) ||
+ if (ParseMDNodeVector(Elts, PFS) ||
ParseToken(lltok::rbrace, "expected end of metadata node"))
return true;
- ID.MDNodeVal = MDNode::get(Context, Elts.data(), Elts.size(),
- isFunctionLocal);
+ ID.MDNodeVal = MDNode::get(Context, Elts.data(), Elts.size());
ID.Kind = ValID::t_MDNode;
return false;
}
@@ -2446,11 +2446,13 @@
}
/// ConvertGlobalOrMetadataValIDToValue - Apply a type to a ValID to get a fully
-/// resolved constant, metadata, or function-local value
+/// resolved constant, metadata, or function-local value. PFS is used to
+/// convert a function-local ValID and can be null when parsing a global or a
+/// non-function-local metadata ValID.
+
bool LLParser::ConvertGlobalOrMetadataValIDToValue(const Type *Ty, ValID &ID,
Value *&V,
- PerFunctionState *PFS,
- bool *isFunctionLocal) {
+ PerFunctionState *PFS) {
switch (ID.Kind) {
case ValID::t_MDNode:
if (!Ty->isMetadataTy())
@@ -2464,10 +2466,9 @@
return false;
case ValID::t_LocalID:
case ValID::t_LocalName:
- if (!PFS || !isFunctionLocal)
+ if (!PFS)
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;
@@ -2527,7 +2528,7 @@
return false;
}
default:
- return ConvertGlobalOrMetadataValIDToValue(Ty, ID, V, &PFS, NULL);
+ return ConvertGlobalOrMetadataValIDToValue(Ty, ID, V, &PFS);
}
return V == 0;
@@ -3858,7 +3859,7 @@
/// Element
/// ::= 'null' | TypeAndValue
bool LLParser::ParseMDNodeVector(SmallVectorImpl<Value*> &Elts,
- PerFunctionState *PFS, bool *isFunctionLocal) {
+ PerFunctionState *PFS) {
do {
// Null is a special case since it is typeless.
if (EatIfPresent(lltok::kw_null)) {
@@ -3870,7 +3871,7 @@
PATypeHolder Ty(Type::getVoidTy(Context));
ValID ID;
if (ParseType(Ty) || ParseValID(ID, PFS) ||
- ConvertGlobalOrMetadataValIDToValue(Ty, ID, V, PFS, isFunctionLocal))
+ ConvertGlobalOrMetadataValIDToValue(Ty, ID, V, PFS))
return true;
Elts.push_back(V);
diff --git a/lib/AsmParser/LLParser.h b/lib/AsmParser/LLParser.h
index d532081..595267b 100644
--- a/lib/AsmParser/LLParser.h
+++ b/lib/AsmParser/LLParser.h
@@ -294,13 +294,11 @@
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,
- bool *isFunctionLocal);
+ Value *&V, PerFunctionState *PFS);
bool ParseGlobalValue(const Type *Ty, Constant *&V);
bool ParseGlobalTypeAndValue(Constant *&V);
bool ParseGlobalValueVector(SmallVectorImpl<Constant*> &Elts);
- bool ParseMDNodeVector(SmallVectorImpl<Value*> &, PerFunctionState *PFS,
- bool *isFunctionLocal);
+ bool ParseMDNodeVector(SmallVectorImpl<Value*> &, PerFunctionState *PFS);
// Function Parsing.
struct ArgInfo {