diff options
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/AsmParser/LLParser.cpp | 10 | ||||
| -rw-r--r-- | llvm/lib/IR/DebugInfo.cpp | 44 | ||||
| -rw-r--r-- | llvm/lib/IR/Verifier.cpp | 1 |
3 files changed, 11 insertions, 44 deletions
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp index 6e79960e3db..ed1d0ff9ee6 100644 --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -3041,7 +3041,9 @@ struct MDConstant : public MDFieldImpl<ConstantAsMetadata *> { MDConstant() : ImplTy(nullptr) {} }; 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>> { MDFieldList() : ImplTy(SmallVector<Metadata *, 4>()) {} @@ -3253,10 +3255,14 @@ bool LLParser::ParseMDField(LocTy Loc, StringRef Name, MDConstant &Result) { template <> bool LLParser::ParseMDField(LocTy Loc, StringRef Name, MDStringField &Result) { + LocTy ValueLoc = Lex.getLoc(); std::string S; if (ParseStringConstant(S)) return true; + if (!Result.AllowEmpty && S.empty()) + return Error(ValueLoc, "'" + Name + "' cannot be empty"); + Result.assign(S.empty() ? nullptr : MDString::get(Context, S)); return false; } @@ -3655,8 +3661,8 @@ bool LLParser::ParseMDTemplateValueParameter(MDNode *&Result, bool IsDistinct) { /// declaration: !3) bool LLParser::ParseMDGlobalVariable(MDNode *&Result, bool IsDistinct) { #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ + REQUIRED(name, MDStringField, (/* AllowEmpty */ false)); \ OPTIONAL(scope, MDField, ); \ - OPTIONAL(name, MDStringField, ); \ OPTIONAL(linkageName, MDStringField, ); \ OPTIONAL(file, MDField, ); \ OPTIONAL(line, LineField, ); \ diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp index 4e5b5f1f975..91823773212 100644 --- a/llvm/lib/IR/DebugInfo.cpp +++ b/llvm/lib/IR/DebugInfo.cpp @@ -275,16 +275,6 @@ bool DISubprogram::Verify() const { if (!N) 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()) return false; @@ -315,38 +305,8 @@ bool DISubprogram::Verify() const { return true; } -bool DIGlobalVariable::Verify() const { - auto *N = dyn_cast_or_null<MDGlobalVariable>(DbgNode); - - 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 DIGlobalVariable::Verify() const { return isGlobalVariable(); } +bool DIVariable::Verify() const { return isVariable(); } bool DILocation::Verify() const { return dyn_cast_or_null<MDLocation>(DbgNode); diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index 4bf24211963..19897d4c030 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -969,6 +969,7 @@ void Verifier::visitMDGlobalVariable(const MDGlobalVariable &N) { visitMDVariable(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()) { Assert(isa<ConstantAsMetadata>(V) && !isa<Function>(cast<ConstantAsMetadata>(V)->getValue()), |

