Verifier: Move more debug info checks away from Verify()

Most of these checks were already in the `Verifier` so this is more of a
cleanup.  Now almost everything is over there.

Now that require a `name:` for `MDGlobalVariable`, add a check in
`LLParser` for it.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@233657 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith 2015-03-31 01:28:22 +00:00
parent 0cbd7fc433
commit c0bf4a0671
6 changed files with 21 additions and 46 deletions

View File

@ -3041,7 +3041,9 @@ struct MDConstant : public MDFieldImpl<ConstantAsMetadata *> {
MDConstant() : ImplTy(nullptr) {} MDConstant() : ImplTy(nullptr) {}
}; };
struct MDStringField : public MDFieldImpl<MDString *> { struct MDStringField : public MDFieldImpl<MDString *> {
MDStringField() : ImplTy(nullptr) {} bool AllowEmpty;
MDStringField(bool AllowEmpty = true)
: ImplTy(nullptr), AllowEmpty(AllowEmpty) {}
}; };
struct MDFieldList : public MDFieldImpl<SmallVector<Metadata *, 4>> { struct MDFieldList : public MDFieldImpl<SmallVector<Metadata *, 4>> {
MDFieldList() : ImplTy(SmallVector<Metadata *, 4>()) {} MDFieldList() : ImplTy(SmallVector<Metadata *, 4>()) {}
@ -3253,10 +3255,14 @@ bool LLParser::ParseMDField(LocTy Loc, StringRef Name, MDConstant &Result) {
template <> template <>
bool LLParser::ParseMDField(LocTy Loc, StringRef Name, MDStringField &Result) { bool LLParser::ParseMDField(LocTy Loc, StringRef Name, MDStringField &Result) {
LocTy ValueLoc = Lex.getLoc();
std::string S; std::string S;
if (ParseStringConstant(S)) if (ParseStringConstant(S))
return true; return true;
if (!Result.AllowEmpty && S.empty())
return Error(ValueLoc, "'" + Name + "' cannot be empty");
Result.assign(S.empty() ? nullptr : MDString::get(Context, S)); Result.assign(S.empty() ? nullptr : MDString::get(Context, S));
return false; return false;
} }
@ -3655,8 +3661,8 @@ bool LLParser::ParseMDTemplateValueParameter(MDNode *&Result, bool IsDistinct) {
/// declaration: !3) /// declaration: !3)
bool LLParser::ParseMDGlobalVariable(MDNode *&Result, bool IsDistinct) { bool LLParser::ParseMDGlobalVariable(MDNode *&Result, bool IsDistinct) {
#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
REQUIRED(name, MDStringField, (/* AllowEmpty */ false)); \
OPTIONAL(scope, MDField, ); \ OPTIONAL(scope, MDField, ); \
OPTIONAL(name, MDStringField, ); \
OPTIONAL(linkageName, MDStringField, ); \ OPTIONAL(linkageName, MDStringField, ); \
OPTIONAL(file, MDField, ); \ OPTIONAL(file, MDField, ); \
OPTIONAL(line, LineField, ); \ OPTIONAL(line, LineField, ); \

View File

@ -275,16 +275,6 @@ bool DISubprogram::Verify() const {
if (!N) if (!N)
return false; return false;
if (!isScopeRef(N->getScope()))
return false;
if (auto *Op = N->getType())
if (!isa<MDNode>(Op))
return false;
if (!isTypeRef(getContainingType()))
return false;
if (isLValueReference() && isRValueReference()) if (isLValueReference() && isRValueReference())
return false; return false;
@ -315,38 +305,8 @@ bool DISubprogram::Verify() const {
return true; return true;
} }
bool DIGlobalVariable::Verify() const { bool DIGlobalVariable::Verify() const { return isGlobalVariable(); }
auto *N = dyn_cast_or_null<MDGlobalVariable>(DbgNode); bool DIVariable::Verify() const { return isVariable(); }
if (!N)
return false;
if (N->getDisplayName().empty())
return false;
if (auto *Op = N->getScope())
if (!isa<MDNode>(Op))
return false;
if (auto *Op = N->getStaticDataMemberDeclaration())
if (!isa<MDNode>(Op))
return false;
return isTypeRef(N->getType());
}
bool DIVariable::Verify() const {
auto *N = dyn_cast_or_null<MDLocalVariable>(DbgNode);
if (!N)
return false;
if (auto *Op = N->getScope())
if (!isa<MDNode>(Op))
return false;
return isTypeRef(N->getType());
}
bool DILocation::Verify() const { bool DILocation::Verify() const {
return dyn_cast_or_null<MDLocation>(DbgNode); return dyn_cast_or_null<MDLocation>(DbgNode);

View File

@ -969,6 +969,7 @@ void Verifier::visitMDGlobalVariable(const MDGlobalVariable &N) {
visitMDVariable(N); visitMDVariable(N);
Assert(N.getTag() == dwarf::DW_TAG_variable, "invalid tag", &N); Assert(N.getTag() == dwarf::DW_TAG_variable, "invalid tag", &N);
Assert(!N.getName().empty(), "missing global variable name", &N);
if (auto *V = N.getRawVariable()) { if (auto *V = N.getRawVariable()) {
Assert(isa<ConstantAsMetadata>(V) && Assert(isa<ConstantAsMetadata>(V) &&
!isa<Function>(cast<ConstantAsMetadata>(V)->getValue()), !isa<Function>(cast<ConstantAsMetadata>(V)->getValue()),

View File

@ -0,0 +1,4 @@
; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
; CHECK: <stdin>:[[@LINE+1]]:30: error: 'name' cannot be empty
!0 = !MDGlobalVariable(name: "")

View File

@ -0,0 +1,4 @@
; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
; CHECK: <stdin>:[[@LINE+1]]:24: error: missing required field 'name'
!0 = !MDGlobalVariable()

View File

@ -17,8 +17,8 @@
file: !2, line: 7, type: !3, isLocal: true, file: !2, line: 7, type: !3, isLocal: true,
isDefinition: false, variable: i32* @foo) isDefinition: false, variable: i32* @foo)
; CHECK: !6 = !MDGlobalVariable(scope: !0, isLocal: false, isDefinition: true) ; CHECK: !6 = !MDGlobalVariable(name: "foo", scope: !0, isLocal: false, isDefinition: true)
!6 = !MDGlobalVariable(scope: !0) !6 = !MDGlobalVariable(name: "foo", scope: !0)
!7 = !MDCompositeType(tag: DW_TAG_structure_type, name: "Class", size: 8, align: 8) !7 = !MDCompositeType(tag: DW_TAG_structure_type, name: "Class", size: 8, align: 8)
!8 = !MDDerivedType(tag: DW_TAG_member, name: "mem", flags: DIFlagStaticMember, scope: !7, baseType: !3) !8 = !MDDerivedType(tag: DW_TAG_member, name: "mem", flags: DIFlagStaticMember, scope: !7, baseType: !3)