Verifier: Check fields of MDVariable subclasses

Check fields from `MDLocalVariable` and `MDGlobalVariable` and change
the accessors to downcast to the right types.  `getType()` still returns
`Metadata*` since it could be an `MDString`-based reference.

Since local variables require non-null scopes, I also updated `LLParser`
to require a `scope:` field.

A number of testcases had grown bitrot and started failing with this
patch; I committed them separately in r233349.  If I just broke your
out-of-tree testcases, you're probably hitting similar problems (so have
a look there).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@233389 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith
2015-03-27 17:29:58 +00:00
parent 2ee615297c
commit a9902daa5c
16 changed files with 205 additions and 107 deletions

View File

@@ -582,9 +582,10 @@ DIGlobalVariable DIBuilder::createGlobalVariable(
MDNode *Decl) {
checkGlobalVariableScope(Context);
auto *N = MDGlobalVariable::get(VMContext, Context, Name, LinkageName, F,
LineNumber, Ty, isLocalToUnit, true,
getConstantOrNull(Val), Decl);
auto *N = MDGlobalVariable::get(
VMContext, cast_or_null<MDScope>(Context.get()), Name, LinkageName, F,
LineNumber, Ty, isLocalToUnit, true, getConstantOrNull(Val),
cast_or_null<MDDerivedType>(Decl));
AllGVs.push_back(N);
return N;
}
@@ -595,9 +596,10 @@ DIGlobalVariable DIBuilder::createTempGlobalVariableFwdDecl(
MDNode *Decl) {
checkGlobalVariableScope(Context);
return MDGlobalVariable::getTemporary(VMContext, Context, Name, LinkageName,
F, LineNumber, Ty, isLocalToUnit, false,
getConstantOrNull(Val), Decl).release();
return MDGlobalVariable::getTemporary(
VMContext, cast_or_null<MDScope>(Context.get()), Name, LinkageName,
F, LineNumber, Ty, isLocalToUnit, false, getConstantOrNull(Val),
cast_or_null<MDDerivedType>(Decl)).release();
}
DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope,
@@ -613,9 +615,9 @@ DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope,
assert((!Context || Context.isScope()) &&
"createLocalVariable should be called with a valid Context");
auto *Node =
MDLocalVariable::get(VMContext, Tag, getNonCompileUnitScope(Scope), Name,
File, LineNo, Ty, ArgNo, Flags);
auto *Node = MDLocalVariable::get(VMContext, Tag,
cast_or_null<MDLocalScope>(Context.get()),
Name, File, LineNo, Ty, ArgNo, Flags);
if (AlwaysPreserve) {
// The optimizer may remove local variable. If there is an interest
// to preserve variable info in such situation then stash it in a