[clang] b9b90bb - [clang] Replace report_fatal_error(std::string) uses with report_fatal_error(Twine)
Simon Pilgrim via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 6 03:45:43 PDT 2021
Author: Simon Pilgrim
Date: 2021-10-06T11:43:19+01:00
New Revision: b9b90bb5426ffc23cf90f133a90d1469d263522c
URL: https://github.com/llvm/llvm-project/commit/b9b90bb5426ffc23cf90f133a90d1469d263522c
DIFF: https://github.com/llvm/llvm-project/commit/b9b90bb5426ffc23cf90f133a90d1469d263522c.diff
LOG: [clang] Replace report_fatal_error(std::string) uses with report_fatal_error(Twine)
As described on D111049, we're trying to remove the <string> dependency from error handling and replace uses of report_fatal_error(const std::string&) with the Twine() variant which can be forward declared.
Added:
Modified:
clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h
clang/include/clang/Serialization/ASTRecordReader.h
clang/lib/Basic/ProfileList.cpp
clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Tooling/CommonOptionsParser.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h b/clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h
index b8ee9972f6f86..c0459cc80ca4c 100644
--- a/clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h
+++ b/clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h
@@ -141,7 +141,7 @@ runCheckOnCode(StringRef Code, std::vector<ClangTidyError> *Errors = nullptr,
for (const auto &Error : DiagConsumer.take()) {
ErrorText += Error.Message.Message + "\n";
}
- llvm::report_fatal_error(ErrorText);
+ llvm::report_fatal_error(llvm::Twine(ErrorText));
}
tooling::Replacements Fixes;
diff --git a/clang/include/clang/Serialization/ASTRecordReader.h b/clang/include/clang/Serialization/ASTRecordReader.h
index b85609bf4e05b..36179ec23408f 100644
--- a/clang/include/clang/Serialization/ASTRecordReader.h
+++ b/clang/include/clang/Serialization/ASTRecordReader.h
@@ -350,7 +350,7 @@ struct SavedStreamPosition {
~SavedStreamPosition() {
if (llvm::Error Err = Cursor.JumpToBit(Offset))
llvm::report_fatal_error(
- "Cursor should always be able to go back, failed: " +
+ llvm::Twine("Cursor should always be able to go back, failed: ") +
toString(std::move(Err)));
}
diff --git a/clang/lib/Basic/ProfileList.cpp b/clang/lib/Basic/ProfileList.cpp
index 2cb05c1c3c073..9c88559d1c333 100644
--- a/clang/lib/Basic/ProfileList.cpp
+++ b/clang/lib/Basic/ProfileList.cpp
@@ -58,7 +58,7 @@ ProfileSpecialCaseList::createOrDie(const std::vector<std::string> &Paths,
std::string Error;
if (auto PSCL = create(Paths, VFS, Error))
return PSCL;
- llvm::report_fatal_error(Error);
+ llvm::report_fatal_error(llvm::Twine(Error));
}
}
diff --git a/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp b/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
index 1adf0ad9c0e5b..acfda02826672 100644
--- a/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
+++ b/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
@@ -264,7 +264,7 @@ class PCHContainerGenerator : public ASTConsumer {
std::string Error;
auto Triple = Ctx.getTargetInfo().getTriple();
if (!llvm::TargetRegistry::lookupTarget(Triple.getTriple(), Error))
- llvm::report_fatal_error(Error);
+ llvm::report_fatal_error(llvm::Twine(Error));
// Emit the serialized Clang AST into its own section.
assert(Buffer->IsComplete && "serialization did not complete");
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp
index 97db833d41ca6..d011d14612d13 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -3851,7 +3851,7 @@ Decl *ASTReader::ReadDeclRecord(DeclID ID) {
Expected<unsigned> MaybeDeclCode = Record.readRecord(DeclsCursor, Code);
if (!MaybeDeclCode)
llvm::report_fatal_error(
- "ASTReader::readDeclRecord failed reading decl code: " +
+ Twine("ASTReader::readDeclRecord failed reading decl code: ") +
toString(MaybeDeclCode.takeError()));
switch ((DeclCode)MaybeDeclCode.get()) {
case DECL_CONTEXT_LEXICAL:
@@ -4236,12 +4236,12 @@ void ASTReader::loadDeclUpdateRecords(PendingUpdateRecord &Record) {
if (llvm::Error JumpFailed = Cursor.JumpToBit(Offset))
// FIXME don't do a fatal error.
llvm::report_fatal_error(
- "ASTReader::loadDeclUpdateRecords failed jumping: " +
+ Twine("ASTReader::loadDeclUpdateRecords failed jumping: ") +
toString(std::move(JumpFailed)));
Expected<unsigned> MaybeCode = Cursor.ReadCode();
if (!MaybeCode)
llvm::report_fatal_error(
- "ASTReader::loadDeclUpdateRecords failed reading code: " +
+ Twine("ASTReader::loadDeclUpdateRecords failed reading code: ") +
toString(MaybeCode.takeError()));
unsigned Code = MaybeCode.get();
ASTRecordReader Record(*this, *F);
@@ -4250,7 +4250,7 @@ void ASTReader::loadDeclUpdateRecords(PendingUpdateRecord &Record) {
"Expected DECL_UPDATES record!");
else
llvm::report_fatal_error(
- "ASTReader::loadDeclUpdateRecords failed reading rec code: " +
+ Twine("ASTReader::loadDeclUpdateRecords failed reading rec code: ") +
toString(MaybeCode.takeError()));
ASTDeclReader Reader(*this, Record, RecordLocation(F, Offset), ID,
@@ -4317,14 +4317,14 @@ void ASTReader::loadPendingDeclChain(Decl *FirstLocal, uint64_t LocalOffset) {
SavedStreamPosition SavedPosition(Cursor);
if (llvm::Error JumpFailed = Cursor.JumpToBit(LocalOffset))
llvm::report_fatal_error(
- "ASTReader::loadPendingDeclChain failed jumping: " +
+ Twine("ASTReader::loadPendingDeclChain failed jumping: ") +
toString(std::move(JumpFailed)));
RecordData Record;
Expected<unsigned> MaybeCode = Cursor.ReadCode();
if (!MaybeCode)
llvm::report_fatal_error(
- "ASTReader::loadPendingDeclChain failed reading code: " +
+ Twine("ASTReader::loadPendingDeclChain failed reading code: ") +
toString(MaybeCode.takeError()));
unsigned Code = MaybeCode.get();
if (Expected<unsigned> MaybeRecCode = Cursor.readRecord(Code, Record))
@@ -4332,7 +4332,7 @@ void ASTReader::loadPendingDeclChain(Decl *FirstLocal, uint64_t LocalOffset) {
"expected LOCAL_REDECLARATIONS record!");
else
llvm::report_fatal_error(
- "ASTReader::loadPendingDeclChain failed reading rec code: " +
+ Twine("ASTReader::loadPendingDeclChain failed reading rec code: ") +
toString(MaybeCode.takeError()));
// FIXME: We have several
diff erent dispatches on decl kind here; maybe
diff --git a/clang/lib/Tooling/CommonOptionsParser.cpp b/clang/lib/Tooling/CommonOptionsParser.cpp
index 6301544dbb280..7d48dd5054649 100644
--- a/clang/lib/Tooling/CommonOptionsParser.cpp
+++ b/clang/lib/Tooling/CommonOptionsParser.cpp
@@ -170,7 +170,7 @@ CommonOptionsParser::CommonOptionsParser(
llvm::Error Err = init(argc, argv, Category, OccurrencesFlag, Overview);
if (Err) {
llvm::report_fatal_error(
- "CommonOptionsParser: failed to parse command-line arguments. " +
+ Twine("CommonOptionsParser: failed to parse command-line arguments. ") +
llvm::toString(std::move(Err)));
}
}
More information about the cfe-commits
mailing list