Index: lib/DebugInfo/DWARF/DWARFVerifier.cpp =================================================================== --- lib/DebugInfo/DWARF/DWARFVerifier.cpp +++ lib/DebugInfo/DWARF/DWARFVerifier.cpp @@ -411,21 +411,35 @@ break; case DW_AT_location: { Optional> Expr = AttrValue.Value.getAsBlock(); - if (!Expr) { - ReportError("DIE has invalid DW_AT_location encoding:"); - break; + auto VerifyLocation = [&](const void *data, size_t len) { + DWARFUnit *U = Die.getDwarfUnit(); + DataExtractor Data(StringRef(reinterpret_cast(data), len), + DCtx.isLittleEndian(), 0); + DWARFExpression Expression(Data, U->getVersion(), + U->getAddressByteSize()); + bool Error = llvm::any_of(Expression, [](DWARFExpression::Operation &Op) { + return Op.isError(); + }); + if (Error) + ReportError("DIE contains invalid DWARF expression:"); + }; + if (Expr) { + // Inlined location + VerifyLocation(Expr->data(), Expr->size()); + } else { + // Location list + if (auto LocOffset = AttrValue.Value.getAsUnsignedConstant()) { + auto DebugLoc = DCtx.getDebugLoc(); + if (DebugLoc) { + auto LocList = DebugLoc->getLocationListAtOffset(*LocOffset); + if (LocList) { + for (const auto &Entry: LocList->Entries) { + VerifyLocation(Entry.Loc.data(), Entry.Loc.size()); + } + } + } + } } - - DWARFUnit *U = Die.getDwarfUnit(); - DataExtractor Data( - StringRef(reinterpret_cast(Expr->data()), Expr->size()), - DCtx.isLittleEndian(), 0); - DWARFExpression Expression(Data, U->getVersion(), U->getAddressByteSize()); - bool Error = llvm::any_of(Expression, [](DWARFExpression::Operation &Op) { - return Op.isError(); - }); - if (Error) - ReportError("DIE contains invalid DWARF expression:"); break; }