diff --git a/clang-tools-extra/clangd/index/Serialization.cpp b/clang-tools-extra/clangd/index/Serialization.cpp --- a/clang-tools-extra/clangd/index/Serialization.cpp +++ b/clang-tools-extra/clangd/index/Serialization.cpp @@ -174,7 +174,7 @@ } if (llvm::zlib::isAvailable()) { llvm::SmallString<1> Compressed; - llvm::cantFail(llvm::zlib::compress(RawTable, Compressed)); + cantFail(llvm::zlib::compress(RawTable, Compressed)); write32(RawTable.size(), OS); OS << Compressed; } else { diff --git a/clang-tools-extra/clangd/refactor/tweaks/ExpandMacro.cpp b/clang-tools-extra/clangd/refactor/tweaks/ExpandMacro.cpp --- a/clang-tools-extra/clangd/refactor/tweaks/ExpandMacro.cpp +++ b/clang-tools-extra/clangd/refactor/tweaks/ExpandMacro.cpp @@ -121,7 +121,7 @@ Expansion.Spelled.back().endLocation()); tooling::Replacements Reps; - llvm::cantFail(Reps.add(tooling::Replacement(SM, MacroRange, Replacement))); + cantFail(Reps.add(tooling::Replacement(SM, MacroRange, Replacement))); return Effect::mainFileEdit(SM, std::move(Reps)); } diff --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp --- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp +++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp @@ -110,7 +110,7 @@ auto File = testPath("foo.cpp"); runAddDocument(Server, File, TestCode); auto CompletionList = - llvm::cantFail(runCodeComplete(Server, File, Point, Opts)); + cantFail(runCodeComplete(Server, File, Point, Opts)); return CompletionList; } @@ -129,7 +129,7 @@ Annotations Test(Text); runAddDocument(Server, File, Test.code()); auto CompletionList = - llvm::cantFail(runCodeComplete(Server, File, Test.point(), Opts)); + cantFail(runCodeComplete(Server, File, Test.point(), Opts)); return CompletionList; } @@ -1045,7 +1045,7 @@ ClangdServer Server(CDB, FS, DiagConsumer, Opts); auto File = testPath("foo.cpp"); runAddDocument(Server, File, Text); - return llvm::cantFail(runSignatureHelp(Server, File, Point)); + return cantFail(runSignatureHelp(Server, File, Point)); } SignatureHelp signatures(llvm::StringRef Text, @@ -2012,7 +2012,7 @@ // Wait for the dynamic index being built. ASSERT_TRUE(Server.blockUntilIdleForTest()); EXPECT_THAT( - llvm::cantFail(runSignatureHelp(Server, File, FileContent.point())) + cantFail(runSignatureHelp(Server, File, FileContent.point())) .signatures, ElementsAre(AllOf(Sig("foo() -> int"), SigDoc("Member doc")))); } diff --git a/clang-tools-extra/clangd/unittests/FormatTests.cpp b/clang-tools-extra/clangd/unittests/FormatTests.cpp --- a/clang-tools-extra/clangd/unittests/FormatTests.cpp +++ b/clang-tools-extra/clangd/unittests/FormatTests.cpp @@ -23,7 +23,7 @@ std::string afterTyped(llvm::StringRef CodeWithCursor, llvm::StringRef Typed) { Annotations Code(CodeWithCursor); - unsigned Cursor = llvm::cantFail(positionToOffset(Code.code(), Code.point())); + unsigned Cursor = cantFail(positionToOffset(Code.code(), Code.point())); auto Changes = formatIncremental(Code.code(), Cursor, Typed, format::getGoogleStyle(format::FormatStyle::LK_Cpp)); diff --git a/clang-tools-extra/clangd/unittests/HeaderSourceSwitchTests.cpp b/clang-tools-extra/clangd/unittests/HeaderSourceSwitchTests.cpp --- a/clang-tools-extra/clangd/unittests/HeaderSourceSwitchTests.cpp +++ b/clang-tools-extra/clangd/unittests/HeaderSourceSwitchTests.cpp @@ -271,7 +271,7 @@ ClangdServer Server(CDB, FS, DiagConsumer, Options); runAddDocument(Server, CppPath, FileContent); EXPECT_EQ(HeaderPath, - *llvm::cantFail(runSwitchHeaderSource(Server, CppPath))); + *cantFail(runSwitchHeaderSource(Server, CppPath))); } } // namespace diff --git a/clang-tools-extra/clangd/unittests/RenameTests.cpp b/clang-tools-extra/clangd/unittests/RenameTests.cpp --- a/clang-tools-extra/clangd/unittests/RenameTests.cpp +++ b/clang-tools-extra/clangd/unittests/RenameTests.cpp @@ -75,7 +75,7 @@ auto RenameResult = renameWithinFile(AST, testPath(TU.Filename), Code.point(), NewName); ASSERT_TRUE(bool(RenameResult)) << RenameResult.takeError(); - auto ApplyResult = llvm::cantFail( + auto ApplyResult = cantFail( tooling::applyAllReplacements(Code.code(), *RenameResult)); EXPECT_EQ(expectedResult(Code, NewName), ApplyResult); } @@ -183,7 +183,7 @@ EXPECT_TRUE(bool(Results)) << "renameWithinFile returned an error: " << llvm::toString(Results.takeError()); auto ApplyResult = - llvm::cantFail(tooling::applyAllReplacements(T.code(), *Results)); + cantFail(tooling::applyAllReplacements(T.code(), *Results)); EXPECT_EQ(expectedResult(T, NewName), ApplyResult); } } diff --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp --- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp +++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp @@ -83,8 +83,8 @@ std::string Result; unsigned NextChar = 0; for (auto &T : Tokens) { - unsigned StartOffset = llvm::cantFail(positionToOffset(Input, T.R.start)); - unsigned EndOffset = llvm::cantFail(positionToOffset(Input, T.R.end)); + unsigned StartOffset = cantFail(positionToOffset(Input, T.R.start)); + unsigned EndOffset = cantFail(positionToOffset(Input, T.R.end)); assert(StartOffset <= EndOffset); assert(NextChar <= StartOffset); diff --git a/clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp b/clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp --- a/clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp +++ b/clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp @@ -141,7 +141,7 @@ for (const char *Test : Tests) { auto T = Annotations(Test); auto AST = TestTU::withCode(T.code()).build(); - EXPECT_THAT(llvm::cantFail(getSemanticRanges(AST, T.point())), + EXPECT_THAT(cantFail(getSemanticRanges(AST, T.point())), ElementsAreArray(T.ranges())) << Test; } diff --git a/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp b/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp --- a/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp +++ b/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp @@ -307,7 +307,7 @@ EXPECT_THAT_EXPECTED(sourceLocationInMainFile(SM, position(5, 0)), Failed()); // Check all positions mentioned in the test return valid results. for (auto P : Source.points()) { - size_t Offset = llvm::cantFail(positionToOffset(Source.code(), P)); + size_t Offset = cantFail(positionToOffset(Source.code(), P)); EXPECT_THAT_EXPECTED(sourceLocationInMainFile(SM, P), HasValue(StartOfFile.getLocWithOffset(Offset))); } diff --git a/clang-tools-extra/clangd/unittests/TweakTesting.cpp b/clang-tools-extra/clangd/unittests/TweakTesting.cpp --- a/clang-tools-extra/clangd/unittests/TweakTesting.cpp +++ b/clang-tools-extra/clangd/unittests/TweakTesting.cpp @@ -140,12 +140,12 @@ llvm::StringRef Code = Test.code(); std::vector Cases; for (const auto& Point : Test.points()) { - size_t Offset = llvm::cantFail(positionToOffset(Code, Point)); + size_t Offset = cantFail(positionToOffset(Code, Point)); Cases.push_back((Code.substr(0, Offset) + "^" + Code.substr(Offset)).str()); } for (const auto& Range : Test.ranges()) { - size_t Begin = llvm::cantFail(positionToOffset(Code, Range.start)); - size_t End = llvm::cantFail(positionToOffset(Code, Range.end)); + size_t Begin = cantFail(positionToOffset(Code, Range.start)); + size_t End = cantFail(positionToOffset(Code, Range.end)); Cases.push_back((Code.substr(0, Begin) + "[[" + Code.substr(Begin, End - Begin) + "]]" + Code.substr(End)) .str()); diff --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp b/clang-tools-extra/clangd/unittests/XRefsTests.cpp --- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp +++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp @@ -2315,7 +2315,7 @@ auto AST = TestTU::withCode(File.code()).build(); ASSERT_TRUE(AST.getDiagnostics().empty()) << AST.getDiagnostics().begin()->Message; - SourceLocation SL = llvm::cantFail( + SourceLocation SL = cantFail( sourceLocationInMainFile(AST.getSourceManager(), File.point())); const FunctionDecl *FD = diff --git a/clang/lib/AST/ExternalASTMerger.cpp b/clang/lib/AST/ExternalASTMerger.cpp --- a/clang/lib/AST/ExternalASTMerger.cpp +++ b/clang/lib/AST/ExternalASTMerger.cpp @@ -510,7 +510,7 @@ Decl *LookupRes = C.first.get(); ASTImporter *Importer = C.second; auto NDOrErr = Importer->Import(LookupRes); - NamedDecl *ND = cast(llvm::cantFail(std::move(NDOrErr))); + NamedDecl *ND = cast(cantFail(std::move(NDOrErr))); assert(ND); // If we don't import specialization, they are not available via lookup // because the lookup result is imported TemplateDecl and it does not diff --git a/clang/lib/Tooling/Core/Replacement.cpp b/clang/lib/Tooling/Core/Replacement.cpp --- a/clang/lib/Tooling/Core/Replacement.cpp +++ b/clang/lib/Tooling/Core/Replacement.cpp @@ -519,7 +519,7 @@ return MergedRanges; tooling::Replacements FakeReplaces; for (const auto &R : MergedRanges) { - llvm::cantFail( + cantFail( FakeReplaces.add(Replacement(Replaces.begin()->getFilePath(), R.getOffset(), R.getLength(), std::string(R.getLength(), ' '))), diff --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp --- a/clang/lib/Tooling/Tooling.cpp +++ b/clang/lib/Tooling/Tooling.cpp @@ -238,7 +238,7 @@ } std::string getAbsolutePath(StringRef File) { - return llvm::cantFail(getAbsolutePath(*llvm::vfs::getRealFileSystem(), File)); + return cantFail(getAbsolutePath(*llvm::vfs::getRealFileSystem(), File)); } void addTargetAndModeForProgramName(std::vector &CommandLine, diff --git a/clang/tools/clang-refactor/ClangRefactor.cpp b/clang/tools/clang-refactor/ClangRefactor.cpp --- a/clang/tools/clang-refactor/ClangRefactor.cpp +++ b/clang/tools/clang-refactor/ClangRefactor.cpp @@ -321,7 +321,7 @@ llvm::errs() << llvm::toString(std::move(Err)) << "\n"; return; } - llvm::cantFail(std::move(Err)); // This is a success. + cantFail(std::move(Err)); // This is a success. DiagnosticBuilder DB( getDiags().Report(Diag->first, Diag->second.getDiagID())); Diag->second.Emit(DB); diff --git a/clang/unittests/Basic/DiagnosticTest.cpp b/clang/unittests/Basic/DiagnosticTest.cpp --- a/clang/unittests/Basic/DiagnosticTest.cpp +++ b/clang/unittests/Basic/DiagnosticTest.cpp @@ -82,7 +82,7 @@ ASSERT_TRUE(!Value); llvm::Error Err = Value.takeError(); Optional ErrDiag = DiagnosticError::take(Err); - llvm::cantFail(std::move(Err)); + cantFail(std::move(Err)); ASSERT_FALSE(!ErrDiag); EXPECT_EQ(ErrDiag->first, SourceLocation()); EXPECT_EQ(ErrDiag->second.getDiagID(), diag::err_cannot_open_file); diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp --- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp @@ -31,7 +31,6 @@ using namespace lldb_private; using namespace lldb; using namespace lldb_private::python; -using llvm::cantFail; using llvm::Error; using llvm::Expected; using llvm::Twine; diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp --- a/lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp @@ -48,20 +48,20 @@ static void ParseCompile3(const CVSymbol &sym, CompilandIndexItem &cci) { cci.m_compile_opts.emplace(); - llvm::cantFail( + cantFail( SymbolDeserializer::deserializeAs(sym, *cci.m_compile_opts)); } static void ParseObjname(const CVSymbol &sym, CompilandIndexItem &cci) { cci.m_obj_name.emplace(); - llvm::cantFail( + cantFail( SymbolDeserializer::deserializeAs(sym, *cci.m_obj_name)); } static void ParseBuildInfo(PdbIndex &index, const CVSymbol &sym, CompilandIndexItem &cci) { BuildInfoSym bis(SymbolRecordKind::BuildInfoSym); - llvm::cantFail(SymbolDeserializer::deserializeAs(sym, bis)); + cantFail(SymbolDeserializer::deserializeAs(sym, bis)); // S_BUILDINFO just points to an LF_BUILDINFO in the IPI stream. Let's do // a little extra work to pull out the LF_BUILDINFO. @@ -72,7 +72,7 @@ return; BuildInfoRecord bir; - llvm::cantFail(TypeDeserializer::deserializeAs(*cvt, bir)); + cantFail(TypeDeserializer::deserializeAs(*cvt, bir)); cci.m_build_info.assign(bir.ArgIndices.begin(), bir.ArgIndices.end()); } @@ -208,9 +208,9 @@ StringIdRecord file_name; CVType dir_cvt = types.getType(item.m_build_info[0]); CVType file_cvt = types.getType(item.m_build_info[2]); - llvm::cantFail( + cantFail( TypeDeserializer::deserializeAs(dir_cvt, working_dir)); - llvm::cantFail( + cantFail( TypeDeserializer::deserializeAs(file_cvt, file_name)); llvm::sys::path::Style style = working_dir.String.startswith("/") diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/DWARFLocationExpression.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/DWARFLocationExpression.cpp --- a/lldb/source/Plugins/SymbolFile/NativePDB/DWARFLocationExpression.cpp +++ b/lldb/source/Plugins/SymbolFile/NativePDB/DWARFLocationExpression.cpp @@ -84,17 +84,17 @@ switch (cvt.kind()) { case LF_MODIFIER: { ModifierRecord mfr; - llvm::cantFail(TypeDeserializer::deserializeAs(cvt, mfr)); + cantFail(TypeDeserializer::deserializeAs(cvt, mfr)); return GetIntegralTypeInfo(mfr.ModifiedType, tpi); } case LF_POINTER: { PointerRecord pr; - llvm::cantFail(TypeDeserializer::deserializeAs(cvt, pr)); + cantFail(TypeDeserializer::deserializeAs(cvt, pr)); return GetIntegralTypeInfo(pr.ReferentType, tpi); } case LF_ENUM: { EnumRecord er; - llvm::cantFail(TypeDeserializer::deserializeAs(cvt, er)); + cantFail(TypeDeserializer::deserializeAs(cvt, er)); return GetIntegralTypeInfo(er.UnderlyingType, tpi); } default: diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp --- a/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp +++ b/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp @@ -415,7 +415,7 @@ CVSymbol s1 = syms.readRecord(x); lldbassert(s1.kind() == S_PUB32); PublicSym32 p1; - llvm::cantFail(SymbolDeserializer::deserializeAs(s1, p1)); + cantFail(SymbolDeserializer::deserializeAs(s1, p1)); if (p1.Segment < y.segment) return true; return p1.Offset < y.offset; @@ -425,7 +425,7 @@ CVSymbol sym = syms.readRecord(*iter); lldbassert(sym.kind() == S_PUB32); PublicSym32 p; - llvm::cantFail(SymbolDeserializer::deserializeAs(sym, p)); + cantFail(SymbolDeserializer::deserializeAs(sym, p)); if (p.Segment == addr.segment && p.Offset == addr.offset) return p; return llvm::None; @@ -614,7 +614,7 @@ case SymbolKind::S_PROCREF: case SymbolKind::S_LPROCREF: { ProcRefSym ref{global.kind()}; - llvm::cantFail( + cantFail( SymbolDeserializer::deserializeAs(global, ref)); PdbCompilandSymId cu_sym_id{ref.modi(), ref.SymOffset}; return GetParentDeclContext(cu_sym_id); @@ -872,7 +872,7 @@ CVSymbol sym = m_index.ReadSymbolRecord(id); lldbassert(sym.kind() == S_UDT); - UDTSym udt = llvm::cantFail(SymbolDeserializer::deserializeAs(sym)); + UDTSym udt = cantFail(SymbolDeserializer::deserializeAs(sym)); clang::DeclContext *scope = GetParentDeclContext(id); @@ -904,14 +904,14 @@ if (cvt.kind() == LF_MODIFIER) { ModifierRecord modifier; - llvm::cantFail( + cantFail( TypeDeserializer::deserializeAs(cvt, modifier)); return CreateModifierType(modifier); } if (cvt.kind() == LF_POINTER) { PointerRecord pointer; - llvm::cantFail( + cantFail( TypeDeserializer::deserializeAs(cvt, pointer)); return CreatePointerType(pointer); } @@ -927,19 +927,19 @@ if (cvt.kind() == LF_ARRAY) { ArrayRecord ar; - llvm::cantFail(TypeDeserializer::deserializeAs(cvt, ar)); + cantFail(TypeDeserializer::deserializeAs(cvt, ar)); return CreateArrayType(ar); } if (cvt.kind() == LF_PROCEDURE) { ProcedureRecord pr; - llvm::cantFail(TypeDeserializer::deserializeAs(cvt, pr)); + cantFail(TypeDeserializer::deserializeAs(cvt, pr)); return CreateFunctionType(pr.ArgumentList, pr.ReturnType, pr.CallConv); } if (cvt.kind() == LF_MFUNCTION) { MemberFunctionRecord mfr; - llvm::cantFail( + cantFail( TypeDeserializer::deserializeAs(cvt, mfr)); return CreateFunctionType(mfr.ArgumentList, mfr.ReturnType, mfr.CallConv); } @@ -994,7 +994,7 @@ CVSymbol cvs = m_index.ReadSymbolRecord(func_id); ProcSym proc(static_cast(cvs.kind())); - llvm::cantFail(SymbolDeserializer::deserializeAs(cvs, proc)); + cantFail(SymbolDeserializer::deserializeAs(cvs, proc)); PdbTypeSymId type_id(proc.FunctionType); clang::QualType qt = GetOrCreateType(type_id); @@ -1131,7 +1131,7 @@ TpiStream &stream = m_index.tpi(); CVType args_cvt = stream.getType(args_type_idx); ArgListRecord args; - llvm::cantFail( + cantFail( TypeDeserializer::deserializeAs(args_cvt, args)); llvm::ArrayRef arg_indices = llvm::makeArrayRef(args.ArgIndices); diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp --- a/lldb/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp +++ b/lldb/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp @@ -55,17 +55,17 @@ case LF_STRUCTURE: case LF_INTERFACE: { ClassRecord cr; - llvm::cantFail(TypeDeserializer::deserializeAs(type, cr)); + cantFail(TypeDeserializer::deserializeAs(type, cr)); return CVTagRecord(std::move(cr)); } case LF_UNION: { UnionRecord ur; - llvm::cantFail(TypeDeserializer::deserializeAs(type, ur)); + cantFail(TypeDeserializer::deserializeAs(type, ur)); return CVTagRecord(std::move(ur)); } case LF_ENUM: { EnumRecord er; - llvm::cantFail(TypeDeserializer::deserializeAs(type, er)); + cantFail(TypeDeserializer::deserializeAs(type, er)); return CVTagRecord(std::move(er)); } default: @@ -354,13 +354,13 @@ case LF_CLASS: case LF_STRUCTURE: case LF_INTERFACE: - llvm::cantFail(TypeDeserializer::deserializeAs(cvt, cr)); + cantFail(TypeDeserializer::deserializeAs(cvt, cr)); return cr.isForwardRef(); case LF_UNION: - llvm::cantFail(TypeDeserializer::deserializeAs(cvt, ur)); + cantFail(TypeDeserializer::deserializeAs(cvt, ur)); return ur.isForwardRef(); case LF_ENUM: - llvm::cantFail(TypeDeserializer::deserializeAs(cvt, er)); + cantFail(TypeDeserializer::deserializeAs(cvt, er)); return er.isForwardRef(); default: return false; @@ -445,7 +445,7 @@ TypeIndex lldb_private::npdb::LookThroughModifierRecord(CVType modifier) { lldbassert(modifier.kind() == LF_MODIFIER); ModifierRecord mr; - llvm::cantFail(TypeDeserializer::deserializeAs(modifier, mr)); + cantFail(TypeDeserializer::deserializeAs(modifier, mr)); return mr.ModifiedType; } @@ -819,12 +819,12 @@ if (!IsForwardRefUdt(cvt)) return id; - return llvm::cantFail(tpi.findFullDeclForForwardRef(id.index)); + return cantFail(tpi.findFullDeclForForwardRef(id.index)); } template static size_t GetSizeOfTypeInternal(CVType cvt) { RecordType record; - llvm::cantFail(TypeDeserializer::deserializeAs(cvt, record)); + cantFail(TypeDeserializer::deserializeAs(cvt, record)); return record.getSize(); } @@ -849,7 +849,7 @@ TypeIndex index = id.index; if (IsForwardRefUdt(index, tpi)) - index = llvm::cantFail(tpi.findFullDeclForForwardRef(index)); + index = cantFail(tpi.findFullDeclForForwardRef(index)); CVType cvt = tpi.getType(index); switch (cvt.kind()) { @@ -857,7 +857,7 @@ return GetSizeOfType({LookThroughModifierRecord(cvt)}, tpi); case LF_ENUM: { EnumRecord record; - llvm::cantFail(TypeDeserializer::deserializeAs(cvt, record)); + cantFail(TypeDeserializer::deserializeAs(cvt, record)); return GetSizeOfType({record.UnderlyingType}, tpi); } case LF_POINTER: diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp --- a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp +++ b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp @@ -631,50 +631,50 @@ if (cvt.kind() == LF_MODIFIER) { ModifierRecord modifier; - llvm::cantFail( + cantFail( TypeDeserializer::deserializeAs(cvt, modifier)); return CreateModifierType(type_id, modifier, ct); } if (cvt.kind() == LF_POINTER) { PointerRecord pointer; - llvm::cantFail( + cantFail( TypeDeserializer::deserializeAs(cvt, pointer)); return CreatePointerType(type_id, pointer, ct); } if (IsClassRecord(cvt.kind())) { ClassRecord cr; - llvm::cantFail(TypeDeserializer::deserializeAs(cvt, cr)); + cantFail(TypeDeserializer::deserializeAs(cvt, cr)); return CreateTagType(type_id, cr, ct); } if (cvt.kind() == LF_ENUM) { EnumRecord er; - llvm::cantFail(TypeDeserializer::deserializeAs(cvt, er)); + cantFail(TypeDeserializer::deserializeAs(cvt, er)); return CreateTagType(type_id, er, ct); } if (cvt.kind() == LF_UNION) { UnionRecord ur; - llvm::cantFail(TypeDeserializer::deserializeAs(cvt, ur)); + cantFail(TypeDeserializer::deserializeAs(cvt, ur)); return CreateTagType(type_id, ur, ct); } if (cvt.kind() == LF_ARRAY) { ArrayRecord ar; - llvm::cantFail(TypeDeserializer::deserializeAs(cvt, ar)); + cantFail(TypeDeserializer::deserializeAs(cvt, ar)); return CreateArrayType(type_id, ar, ct); } if (cvt.kind() == LF_PROCEDURE) { ProcedureRecord pr; - llvm::cantFail(TypeDeserializer::deserializeAs(cvt, pr)); + cantFail(TypeDeserializer::deserializeAs(cvt, pr)); return CreateProcedureType(type_id, pr, ct); } if (cvt.kind() == LF_MFUNCTION) { MemberFunctionRecord mfr; - llvm::cantFail(TypeDeserializer::deserializeAs(cvt, mfr)); + cantFail(TypeDeserializer::deserializeAs(cvt, mfr)); return CreateFunctionType(type_id, mfr, ct); } @@ -758,7 +758,7 @@ LLVM_FALLTHROUGH; case S_LDATA32: { DataSym ds(sym.kind()); - llvm::cantFail(SymbolDeserializer::deserializeAs(sym, ds)); + cantFail(SymbolDeserializer::deserializeAs(sym, ds)); ti = ds.Type; scope = (sym.kind() == S_GDATA32) ? eValueTypeVariableGlobal : eValueTypeVariableStatic; @@ -773,7 +773,7 @@ LLVM_FALLTHROUGH; case S_LTHREAD32: { ThreadLocalDataSym tlds(sym.kind()); - llvm::cantFail( + cantFail( SymbolDeserializer::deserializeAs(sym, tlds)); ti = tlds.Type; name = tlds.Name; @@ -822,7 +822,7 @@ TpiStream &tpi = m_index->tpi(); ConstantSym constant(cvs.kind()); - llvm::cantFail(SymbolDeserializer::deserializeAs(cvs, constant)); + cantFail(SymbolDeserializer::deserializeAs(cvs, constant)); std::string global_name("::"); global_name += constant.Name; PdbTypeSymId tid(constant.Type, false); @@ -1303,7 +1303,7 @@ if (sym.kind() != S_UDT) continue; - UDTSym udt = llvm::cantFail(SymbolDeserializer::deserializeAs(sym)); + UDTSym udt = cantFail(SymbolDeserializer::deserializeAs(sym)); bool is_typedef = true; if (IsTagRecord(PdbTypeSymId{udt.Type, false}, m_index->tpi())) { CVType cvt = m_index->tpi().getType(udt.Type); @@ -1376,7 +1376,7 @@ CVSymbol sym = m_index->ReadSymbolRecord(id); lldbassert(sym.kind() == SymbolKind::S_UDT); - UDTSym udt = llvm::cantFail(SymbolDeserializer::deserializeAs(sym)); + UDTSym udt = cantFail(SymbolDeserializer::deserializeAs(sym)); TypeSP target_type = GetOrCreateType(udt.Type); diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp --- a/lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp +++ b/lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp @@ -35,14 +35,14 @@ CVType cvt = m_tpi.getType(m_id.index); switch (cvt.kind()) { case LF_ENUM: - llvm::cantFail(TypeDeserializer::deserializeAs(cvt, m_cvr.er)); + cantFail(TypeDeserializer::deserializeAs(cvt, m_cvr.er)); break; case LF_UNION: - llvm::cantFail(TypeDeserializer::deserializeAs(cvt, m_cvr.ur)); + cantFail(TypeDeserializer::deserializeAs(cvt, m_cvr.ur)); break; case LF_CLASS: case LF_STRUCTURE: - llvm::cantFail(TypeDeserializer::deserializeAs(cvt, m_cvr.cr)); + cantFail(TypeDeserializer::deserializeAs(cvt, m_cvr.cr)); break; default: llvm_unreachable("unreachable!"); @@ -152,7 +152,7 @@ CVType cvt = m_tpi.getType(ti); if (cvt.kind() == LF_BITFIELD) { BitFieldRecord bfr; - llvm::cantFail(TypeDeserializer::deserializeAs(cvt, bfr)); + cantFail(TypeDeserializer::deserializeAs(cvt, bfr)); offset += bfr.BitOffset; bitfield_width = bfr.BitSize; ti = bfr.Type; @@ -191,7 +191,7 @@ assert(method_list_type.kind() == LF_METHODLIST); MethodOverloadListRecord method_list; - llvm::cantFail(TypeDeserializer::deserializeAs( + cantFail(TypeDeserializer::deserializeAs( method_list_type, method_list)); for (const OneMethodRecord &method : method_list.Methods) diff --git a/lldb/unittests/Target/ExecutionContextTest.cpp b/lldb/unittests/Target/ExecutionContextTest.cpp --- a/lldb/unittests/Target/ExecutionContextTest.cpp +++ b/lldb/unittests/Target/ExecutionContextTest.cpp @@ -32,7 +32,7 @@ class ExecutionContextTest : public ::testing::Test { public: void SetUp() override { - llvm::cantFail(Reproducer::Initialize(ReproducerMode::Off, llvm::None)); + cantFail(Reproducer::Initialize(ReproducerMode::Off, llvm::None)); FileSystem::Initialize(); HostInfo::Initialize(); platform_linux::PlatformLinux::Initialize(); diff --git a/llvm/include/llvm/Support/Error.h b/llvm/include/llvm/Support/Error.h --- a/llvm/include/llvm/Support/Error.h +++ b/llvm/include/llvm/Support/Error.h @@ -687,6 +687,23 @@ LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag = true); +namespace detail { + +inline LLVM_ATTRIBUTE_NORETURN void +handleError(Error Err, const char *Msg, const char *file, unsigned line) { + if (!Msg) + Msg = "Failure value returned from cantFail wrapped call"; +#ifndef NDEBUG + std::string Str; + raw_string_ostream OS(Str); + OS << Err << "\n" << Msg; + if (file) + OS << " at " << file << ":" << line; + Msg = OS.str().c_str(); +#endif + llvm_unreachable(Msg); +} + /// Report a fatal error if Err is a failure value. /// /// This function can be used to wrap calls to fallible functions ONLY when it @@ -700,18 +717,10 @@ /// /// cantFail(foo(false)); /// @endcode -inline void cantFail(Error Err, const char *Msg = nullptr) { - if (Err) { - if (!Msg) - Msg = "Failure value returned from cantFail wrapped call"; -#ifndef NDEBUG - std::string Str; - raw_string_ostream OS(Str); - OS << Msg << "\n" << Err; - Msg = OS.str().c_str(); -#endif - llvm_unreachable(Msg); - } +inline void cantFail(const char *file, unsigned line, Error Err, + const char *Msg = nullptr) { + if (Err) + handleError(std::move(Err), Msg, file, line); } /// Report a fatal error if ValOrErr is a failure value, otherwise unwraps and @@ -728,21 +737,11 @@ /// int X = cantFail(foo(false)); /// @endcode template -T cantFail(Expected ValOrErr, const char *Msg = nullptr) { +T cantFail(const char *file, unsigned line, Expected ValOrErr, + const char *Msg = nullptr) { if (ValOrErr) return std::move(*ValOrErr); - else { - if (!Msg) - Msg = "Failure value returned from cantFail wrapped call"; -#ifndef NDEBUG - std::string Str; - raw_string_ostream OS(Str); - auto E = ValOrErr.takeError(); - OS << Msg << "\n" << E; - Msg = OS.str().c_str(); -#endif - llvm_unreachable(Msg); - } + handleError(std::move(ValOrErr.takeError()), Msg, file, line); } /// Report a fatal error if ValOrErr is a failure value, otherwise unwraps and @@ -759,22 +758,19 @@ /// Bar &X = cantFail(foo(false)); /// @endcode template -T& cantFail(Expected ValOrErr, const char *Msg = nullptr) { +T &cantFail(const char *file, unsigned line, Expected ValOrErr, + const char *Msg = nullptr) { if (ValOrErr) return *ValOrErr; - else { - if (!Msg) - Msg = "Failure value returned from cantFail wrapped call"; + handleError(std::move(ValOrErr.takeError()), Msg, file, line); +} +} // namespace detail + #ifndef NDEBUG - std::string Str; - raw_string_ostream OS(Str); - auto E = ValOrErr.takeError(); - OS << Msg << "\n" << E; - Msg = OS.str().c_str(); +#define cantFail(...) ::llvm::detail::cantFail(__FILE__, __LINE__, __VA_ARGS__) +#else +#define cantFail(...) ::llvm::detail::cantFail(nullptr, 0, __VA_ARGS__) #endif - llvm_unreachable(Msg); - } -} /// Helper for testing applicability of, and applying, handlers for /// ErrorInfo types. diff --git a/llvm/unittests/Support/ErrorTest.cpp b/llvm/unittests/Support/ErrorTest.cpp --- a/llvm/unittests/Support/ErrorTest.cpp +++ b/llvm/unittests/Support/ErrorTest.cpp @@ -390,8 +390,8 @@ }; EXPECT_DEATH(FailToHandle(), - "Failure value returned from cantFail wrapped call\n" - "CustomError \\{7\\}") + "CustomError \\{7\\}\n" + "Failure value returned from cantFail wrapped call") << "Unhandled Error in handleAllErrors call did not cause an " "abort()"; } @@ -410,8 +410,8 @@ }; EXPECT_DEATH(ReturnErrorFromHandler(), - "Failure value returned from cantFail wrapped call\n" - "CustomError \\{7\\}") + "CustomError \\{7\\}\n" + "Failure value returned from cantFail wrapped call") << " Error returned from handler in handleAllErrors call did not " "cause abort()"; } @@ -515,8 +515,8 @@ EXPECT_DEATH(cantFail(make_error("Original error message", inconvertibleErrorCode()), "Cantfail call failed"), - "Cantfail call failed\n" - "Original error message") + "Original error message\n" + "Cantfail call failed") << "cantFail(Error) did not cause an abort for failure value"; EXPECT_DEATH( @@ -530,6 +530,24 @@ } #endif +TEST(Error, CantFailSourceLocation) { + std::string ErrStr; + raw_string_ostream OS(ErrStr); + OS << "\nFailure value returned from cantFail wrapped call"; + +#if defined(NDEBUG) + // __FILE__ and __LINE_ not added + OS << "\n"; + EXPECT_DEATH(cantFail(make_error(1)), OS.str()) + << "cantFail(Error) did not cause an abort for failure value"; +#else + // __FILE__ and __LINE__ added + int Line = __LINE__; + OS << " at " << __FILE__ << ":" << (Line + 2) << "\n"; + EXPECT_DEATH(cantFail(make_error(1)), OS.str()) + << "cantFail(Error) did not cause an abort for failure value"; +#endif +} // Test Checked Expected in success mode. TEST(Error, CheckedExpectedInSuccessMode) {