From 6da3d8b19c32c76bb503b1a71fc167a0487ef200 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 28 Jul 2021 09:31:14 -0700 Subject: [PATCH] [llvm] Replace LLVM_ATTRIBUTE_NORETURN with C++11 [[noreturn]] [[noreturn]] can be used since Oct 2016 when the minimum compiler requirement was bumped to GCC 4.8/MSVC 2015. Note: the definition of LLVM_ATTRIBUTE_NORETURN is kept for now. --- llvm/include/llvm/MC/MCContext.h | 2 +- .../llvm/Support/CrashRecoveryContext.h | 3 +- llvm/include/llvm/Support/Error.h | 10 ++-- llvm/include/llvm/Support/ErrorHandling.h | 22 ++++---- llvm/include/llvm/Support/Process.h | 6 +-- .../llvm/Support/Windows/WindowsSupport.h | 2 +- llvm/include/llvm/TableGen/Error.h | 22 +++----- llvm/lib/LTO/LTOBackend.cpp | 2 +- llvm/lib/Support/CrashRecoveryContext.cpp | 3 +- llvm/lib/Support/Process.cpp | 3 +- llvm/lib/Support/SmallVector.cpp | 5 +- llvm/lib/Support/Unix/Process.inc | 3 +- llvm/lib/Support/Unix/Unix.h | 3 +- llvm/lib/Support/Windows/Process.inc | 3 +- .../MCTargetDesc/HexagonMCCodeEmitter.cpp | 3 +- llvm/lib/Transforms/Coroutines/Coroutines.cpp | 4 +- llvm/tools/llc/llc.cpp | 5 +- llvm/tools/lli/lli.cpp | 3 +- llvm/tools/llvm-ar/llvm-ar.cpp | 4 +- llvm/tools/llvm-cvtres/llvm-cvtres.cpp | 2 +- llvm/tools/llvm-cxxdump/llvm-cxxdump.cpp | 2 +- llvm/tools/llvm-ifs/ErrorCollector.cpp | 2 +- llvm/tools/llvm-ifs/ErrorCollector.h | 2 +- llvm/tools/llvm-lipo/llvm-lipo.cpp | 51 +++++++++---------- llvm/tools/llvm-mt/llvm-mt.cpp | 2 +- llvm/tools/llvm-objdump/llvm-objdump.cpp | 11 ++-- llvm/tools/llvm-objdump/llvm-objdump.h | 8 +-- llvm/tools/llvm-profgen/ErrorHandling.h | 12 ++--- llvm/tools/llvm-rc/llvm-rc.cpp | 2 +- llvm/tools/llvm-readobj/llvm-readobj.cpp | 4 +- llvm/tools/llvm-readobj/llvm-readobj.h | 2 +- llvm/tools/llvm-strings/llvm-strings.cpp | 2 +- llvm/tools/split-file/split-file.cpp | 3 +- 33 files changed, 94 insertions(+), 119 deletions(-) diff --git a/llvm/include/llvm/MC/MCContext.h b/llvm/include/llvm/MC/MCContext.h index 877b2dc4ac92..bde750759a0b 100644 --- a/llvm/include/llvm/MC/MCContext.h +++ b/llvm/include/llvm/MC/MCContext.h @@ -817,7 +817,7 @@ namespace llvm { // Unrecoverable error has occurred. Display the best diagnostic we can // and bail via exit(1). For now, most MC backend errors are unrecoverable. // FIXME: We should really do something about that. - LLVM_ATTRIBUTE_NORETURN void reportFatalError(SMLoc L, const Twine &Msg); + [[noreturn]] void reportFatalError(SMLoc L, const Twine &Msg); const MCAsmMacro *lookupMacro(StringRef Name) { StringMap::iterator I = MacroMap.find(Name); diff --git a/llvm/include/llvm/Support/CrashRecoveryContext.h b/llvm/include/llvm/Support/CrashRecoveryContext.h index 498690655fd1..2604ccb38431 100644 --- a/llvm/include/llvm/Support/CrashRecoveryContext.h +++ b/llvm/include/llvm/Support/CrashRecoveryContext.h @@ -99,8 +99,7 @@ public: /// Explicitly trigger a crash recovery in the current process, and /// return failure from RunSafely(). This function does not return. - LLVM_ATTRIBUTE_NORETURN - void HandleExit(int RetCode); + [[noreturn]] void HandleExit(int RetCode); /// Throw again a signal or an exception, after it was catched once by a /// CrashRecoveryContext. diff --git a/llvm/include/llvm/Support/Error.h b/llvm/include/llvm/Support/Error.h index e8f340e452ef..4708d5bd6d57 100644 --- a/llvm/include/llvm/Support/Error.h +++ b/llvm/include/llvm/Support/Error.h @@ -257,8 +257,7 @@ private: // of debug prints can cause the function to be too large for inlining. So // it's important that we define this function out of line so that it can't be // inlined. - LLVM_ATTRIBUTE_NORETURN - void fatalUncheckedError() const; + [[noreturn]] void fatalUncheckedError() const; #endif void assertIsChecked() { @@ -688,9 +687,7 @@ private: } #if LLVM_ENABLE_ABI_BREAKING_CHECKS - LLVM_ATTRIBUTE_NORETURN - LLVM_ATTRIBUTE_NOINLINE - void fatalUncheckedExpected() const { + [[noreturn]] LLVM_ATTRIBUTE_NOINLINE void fatalUncheckedExpected() const { dbgs() << "Expected must be checked before access or destruction.\n"; if (HasError) { dbgs() << "Unchecked Expected contained error:\n"; @@ -722,8 +719,7 @@ private: /// Report a serious error, calling any installed error handler. See /// ErrorHandling.h. -LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, - bool gen_crash_diag = true); +[[noreturn]] void report_fatal_error(Error Err, bool gen_crash_diag = true); /// Report a fatal error if Err is a failure value. /// diff --git a/llvm/include/llvm/Support/ErrorHandling.h b/llvm/include/llvm/Support/ErrorHandling.h index 0ec0242d569d..81cac477cb69 100644 --- a/llvm/include/llvm/Support/ErrorHandling.h +++ b/llvm/include/llvm/Support/ErrorHandling.h @@ -68,14 +68,14 @@ class StringRef; /// standard error, followed by a newline. /// After the error handler is called this function will call abort(), it /// does not return. -LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, - bool gen_crash_diag = true); -LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const std::string &reason, - bool gen_crash_diag = true); -LLVM_ATTRIBUTE_NORETURN void report_fatal_error(StringRef reason, - bool gen_crash_diag = true); -LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const Twine &reason, - bool gen_crash_diag = true); +[[noreturn]] void report_fatal_error(const char *reason, + bool gen_crash_diag = true); +[[noreturn]] void report_fatal_error(const std::string &reason, + bool gen_crash_diag = true); +[[noreturn]] void report_fatal_error(StringRef reason, + bool gen_crash_diag = true); +[[noreturn]] void report_fatal_error(const Twine &reason, + bool gen_crash_diag = true); /// Installs a new bad alloc error handler that should be used whenever a /// bad alloc error, e.g. failing malloc/calloc, is encountered by LLVM. @@ -113,13 +113,13 @@ void install_out_of_memory_new_handler(); /// If no error handler is installed (default), throws a bad_alloc exception /// if LLVM is compiled with exception support. Otherwise prints the error /// to standard error and calls abort(). -LLVM_ATTRIBUTE_NORETURN void report_bad_alloc_error(const char *Reason, - bool GenCrashDiag = true); +[[noreturn]] void report_bad_alloc_error(const char *Reason, + bool GenCrashDiag = true); /// This function calls abort(), and prints the optional message to stderr. /// Use the llvm_unreachable macro (that adds location info), instead of /// calling this function directly. -LLVM_ATTRIBUTE_NORETURN void +[[noreturn]] void llvm_unreachable_internal(const char *msg = nullptr, const char *file = nullptr, unsigned line = 0); } diff --git a/llvm/include/llvm/Support/Process.h b/llvm/include/llvm/Support/Process.h index 6687e5e7ff9a..ee03efeed9b2 100644 --- a/llvm/include/llvm/Support/Process.h +++ b/llvm/include/llvm/Support/Process.h @@ -214,12 +214,10 @@ public: /// In that case, the control flow will resume after RunSafely(), like for a /// crash, rather than exiting the current process. /// Use \arg NoCleanup for calling _exit() instead of exit(). - LLVM_ATTRIBUTE_NORETURN - static void Exit(int RetCode, bool NoCleanup = false); + [[noreturn]] static void Exit(int RetCode, bool NoCleanup = false); private: - LLVM_ATTRIBUTE_NORETURN - static void ExitNoCleanup(int RetCode); + [[noreturn]] static void ExitNoCleanup(int RetCode); }; } diff --git a/llvm/include/llvm/Support/Windows/WindowsSupport.h b/llvm/include/llvm/Support/Windows/WindowsSupport.h index a45eeaba4ad5..e03d0dade1ab 100644 --- a/llvm/include/llvm/Support/Windows/WindowsSupport.h +++ b/llvm/include/llvm/Support/Windows/WindowsSupport.h @@ -68,7 +68,7 @@ llvm::VersionTuple GetWindowsOSVersion(); bool MakeErrMsg(std::string *ErrMsg, const std::string &prefix); // Include GetLastError() in a fatal error message. -LLVM_ATTRIBUTE_NORETURN inline void ReportLastErrorFatal(const char *Msg) { +[[noreturn]] inline void ReportLastErrorFatal(const char *Msg) { std::string ErrMsg; MakeErrMsg(&ErrMsg, Msg); llvm::report_fatal_error(ErrMsg); diff --git a/llvm/include/llvm/TableGen/Error.h b/llvm/include/llvm/TableGen/Error.h index a0e23aca211e..da0132b10f4f 100644 --- a/llvm/include/llvm/TableGen/Error.h +++ b/llvm/include/llvm/TableGen/Error.h @@ -22,13 +22,10 @@ namespace llvm { void PrintNote(const Twine &Msg); void PrintNote(ArrayRef NoteLoc, const Twine &Msg); -LLVM_ATTRIBUTE_NORETURN void PrintFatalNote(const Twine &Msg); -LLVM_ATTRIBUTE_NORETURN void PrintFatalNote(ArrayRef ErrorLoc, - const Twine &Msg); -LLVM_ATTRIBUTE_NORETURN void PrintFatalNote(const Record *Rec, - const Twine &Msg); -LLVM_ATTRIBUTE_NORETURN void PrintFatalNote(const RecordVal *RecVal, - const Twine &Msg); +[[noreturn]] void PrintFatalNote(const Twine &Msg); +[[noreturn]] void PrintFatalNote(ArrayRef ErrorLoc, const Twine &Msg); +[[noreturn]] void PrintFatalNote(const Record *Rec, const Twine &Msg); +[[noreturn]] void PrintFatalNote(const RecordVal *RecVal, const Twine &Msg); void PrintWarning(const Twine &Msg); void PrintWarning(ArrayRef WarningLoc, const Twine &Msg); @@ -40,13 +37,10 @@ void PrintError(const char *Loc, const Twine &Msg); void PrintError(const Record *Rec, const Twine &Msg); void PrintError(const RecordVal *RecVal, const Twine &Msg); -LLVM_ATTRIBUTE_NORETURN void PrintFatalError(const Twine &Msg); -LLVM_ATTRIBUTE_NORETURN void PrintFatalError(ArrayRef ErrorLoc, - const Twine &Msg); -LLVM_ATTRIBUTE_NORETURN void PrintFatalError(const Record *Rec, - const Twine &Msg); -LLVM_ATTRIBUTE_NORETURN void PrintFatalError(const RecordVal *RecVal, - const Twine &Msg); +[[noreturn]] void PrintFatalError(const Twine &Msg); +[[noreturn]] void PrintFatalError(ArrayRef ErrorLoc, const Twine &Msg); +[[noreturn]] void PrintFatalError(const Record *Rec, const Twine &Msg); +[[noreturn]] void PrintFatalError(const RecordVal *RecVal, const Twine &Msg); void CheckAssert(SMLoc Loc, Init *Condition, Init *Message); diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp index 4e4ba4f3a58e..2840940b2978 100644 --- a/llvm/lib/LTO/LTOBackend.cpp +++ b/llvm/lib/LTO/LTOBackend.cpp @@ -74,7 +74,7 @@ static cl::opt ThinLTOAssumeMerged( cl::desc("Assume the input has already undergone ThinLTO function " "importing and the other pre-optimization pipeline changes.")); -LLVM_ATTRIBUTE_NORETURN static void reportOpenError(StringRef Path, Twine Msg) { +[[noreturn]] static void reportOpenError(StringRef Path, Twine Msg) { errs() << "failed to open " << Path << ": " << Msg << '\n'; errs().flush(); exit(1); diff --git a/llvm/lib/Support/CrashRecoveryContext.cpp b/llvm/lib/Support/CrashRecoveryContext.cpp index 433d99df5932..b6aaf373a522 100644 --- a/llvm/lib/Support/CrashRecoveryContext.cpp +++ b/llvm/lib/Support/CrashRecoveryContext.cpp @@ -428,8 +428,7 @@ bool CrashRecoveryContext::RunSafely(function_ref Fn) { #endif // !_MSC_VER -LLVM_ATTRIBUTE_NORETURN -void CrashRecoveryContext::HandleExit(int RetCode) { +[[noreturn]] void CrashRecoveryContext::HandleExit(int RetCode) { #if defined(_WIN32) // SEH and VEH ::RaiseException(0xE0000000 | RetCode, 0, 0, NULL); diff --git a/llvm/lib/Support/Process.cpp b/llvm/lib/Support/Process.cpp index e7e9a8b56f74..547b3b73eec2 100644 --- a/llvm/lib/Support/Process.cpp +++ b/llvm/lib/Support/Process.cpp @@ -92,8 +92,7 @@ static bool coreFilesPrevented = !LLVM_ENABLE_CRASH_DUMPS; bool Process::AreCoreFilesPrevented() { return coreFilesPrevented; } -LLVM_ATTRIBUTE_NORETURN -void Process::Exit(int RetCode, bool NoCleanup) { +[[noreturn]] void Process::Exit(int RetCode, bool NoCleanup) { if (CrashRecoveryContext *CRC = CrashRecoveryContext::GetCurrent()) CRC->HandleExit(RetCode); diff --git a/llvm/lib/Support/SmallVector.cpp b/llvm/lib/Support/SmallVector.cpp index 0005f7840912..0e2378b24c38 100644 --- a/llvm/lib/Support/SmallVector.cpp +++ b/llvm/lib/Support/SmallVector.cpp @@ -47,8 +47,7 @@ static_assert(sizeof(SmallVector) == /// Report that MinSize doesn't fit into this vector's size type. Throws /// std::length_error or calls report_fatal_error. -LLVM_ATTRIBUTE_NORETURN -static void report_size_overflow(size_t MinSize, size_t MaxSize); +[[noreturn]] static void report_size_overflow(size_t MinSize, size_t MaxSize); static void report_size_overflow(size_t MinSize, size_t MaxSize) { std::string Reason = "SmallVector unable to grow. Requested capacity (" + std::to_string(MinSize) + @@ -63,7 +62,7 @@ static void report_size_overflow(size_t MinSize, size_t MaxSize) { /// Report that this vector is already at maximum capacity. Throws /// std::length_error or calls report_fatal_error. -LLVM_ATTRIBUTE_NORETURN static void report_at_maximum_capacity(size_t MaxSize); +[[noreturn]] static void report_at_maximum_capacity(size_t MaxSize); static void report_at_maximum_capacity(size_t MaxSize) { std::string Reason = "SmallVector capacity unable to grow. Already at maximum size " + diff --git a/llvm/lib/Support/Unix/Process.inc b/llvm/lib/Support/Unix/Process.inc index 30b957e6a1c4..d3d9fb7d7187 100644 --- a/llvm/lib/Support/Unix/Process.inc +++ b/llvm/lib/Support/Unix/Process.inc @@ -461,5 +461,4 @@ unsigned llvm::sys::Process::GetRandomNumber() { #endif } -LLVM_ATTRIBUTE_NORETURN -void Process::ExitNoCleanup(int RetCode) { _Exit(RetCode); } +[[noreturn]] void Process::ExitNoCleanup(int RetCode) { _Exit(RetCode); } diff --git a/llvm/lib/Support/Unix/Unix.h b/llvm/lib/Support/Unix/Unix.h index 60929139598b..e3924345ddb5 100644 --- a/llvm/lib/Support/Unix/Unix.h +++ b/llvm/lib/Support/Unix/Unix.h @@ -67,8 +67,7 @@ static inline bool MakeErrMsg( } // Include StrError(errnum) in a fatal error message. -LLVM_ATTRIBUTE_NORETURN static inline void ReportErrnumFatal(const char *Msg, - int errnum) { +[[noreturn]] static inline void ReportErrnumFatal(const char *Msg, int errnum) { std::string ErrMsg; MakeErrMsg(&ErrMsg, Msg, errnum); llvm::report_fatal_error(ErrMsg); diff --git a/llvm/lib/Support/Windows/Process.inc b/llvm/lib/Support/Windows/Process.inc index 6f58c52e0746..a0d94e6e253b 100644 --- a/llvm/lib/Support/Windows/Process.inc +++ b/llvm/lib/Support/Windows/Process.inc @@ -504,8 +504,7 @@ bool llvm::RunningWindows8OrGreater() { return GetWindowsOSVersion() >= llvm::VersionTuple(6, 2, 0, 0); } -LLVM_ATTRIBUTE_NORETURN -void Process::ExitNoCleanup(int RetCode) { +[[noreturn]] void Process::ExitNoCleanup(int RetCode) { TerminateProcess(GetCurrentProcess(), RetCode); llvm_unreachable("TerminateProcess doesn't return"); } diff --git a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCCodeEmitter.cpp b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCCodeEmitter.cpp index 24169c83bdb9..4779fa4f262f 100644 --- a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCCodeEmitter.cpp +++ b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCCodeEmitter.cpp @@ -448,8 +448,7 @@ void HexagonMCCodeEmitter::EncodeSingleInstruction(const MCInst &MI, ++MCNumEmitted; } -LLVM_ATTRIBUTE_NORETURN -static void raise_relocation_error(unsigned Width, unsigned Kind) { +[[noreturn]] static void raise_relocation_error(unsigned Width, unsigned Kind) { std::string Text; raw_string_ostream Stream(Text); Stream << "Unrecognized relocation combination: width=" << Width diff --git a/llvm/lib/Transforms/Coroutines/Coroutines.cpp b/llvm/lib/Transforms/Coroutines/Coroutines.cpp index ae2d9e192c87..c131e29300e6 100644 --- a/llvm/lib/Transforms/Coroutines/Coroutines.cpp +++ b/llvm/lib/Transforms/Coroutines/Coroutines.cpp @@ -571,8 +571,8 @@ void coro::Shape::emitDealloc(IRBuilder<> &Builder, Value *Ptr, llvm_unreachable("Unknown coro::ABI enum"); } -LLVM_ATTRIBUTE_NORETURN -static void fail(const Instruction *I, const char *Reason, Value *V) { +[[noreturn]] static void fail(const Instruction *I, const char *Reason, + Value *V) { #ifndef NDEBUG I->dump(); if (V) { diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp index 6a1e2bae2096..58f19b2c6d4b 100644 --- a/llvm/tools/llc/llc.cpp +++ b/llvm/tools/llc/llc.cpp @@ -201,8 +201,7 @@ static cl::opt> RunPass( static int compileModule(char **, LLVMContext &); -LLVM_ATTRIBUTE_NORETURN static void reportError(Twine Msg, - StringRef Filename = "") { +[[noreturn]] static void reportError(Twine Msg, StringRef Filename = "") { SmallString<256> Prefix; if (!Filename.empty()) { if (Filename == "-") @@ -213,7 +212,7 @@ LLVM_ATTRIBUTE_NORETURN static void reportError(Twine Msg, exit(1); } -LLVM_ATTRIBUTE_NORETURN static void reportError(Error Err, StringRef Filename) { +[[noreturn]] static void reportError(Error Err, StringRef Filename) { assert(Err); handleAllErrors(createFileError(Filename, std::move(Err)), [&](const ErrorInfoBase &EI) { reportError(EI.message()); }); diff --git a/llvm/tools/lli/lli.cpp b/llvm/tools/lli/lli.cpp index af614c01b9a8..170cc3b42193 100644 --- a/llvm/tools/lli/lli.cpp +++ b/llvm/tools/lli/lli.cpp @@ -410,8 +410,7 @@ CodeGenOpt::Level getOptLevel() { llvm_unreachable("Unrecognized opt level."); } -LLVM_ATTRIBUTE_NORETURN -static void reportError(SMDiagnostic Err, const char *ProgName) { +[[noreturn]] static void reportError(SMDiagnostic Err, const char *ProgName) { Err.print(ProgName, errs()); exit(1); } diff --git a/llvm/tools/llvm-ar/llvm-ar.cpp b/llvm/tools/llvm-ar/llvm-ar.cpp index 0e1dce6bc2e8..68084ba28dae 100644 --- a/llvm/tools/llvm-ar/llvm-ar.cpp +++ b/llvm/tools/llvm-ar/llvm-ar.cpp @@ -136,14 +136,14 @@ static unsigned MRILineNumber; static bool ParsingMRIScript; // Show the error plus the usage message, and exit. -LLVM_ATTRIBUTE_NORETURN static void badUsage(Twine Error) { +[[noreturn]] static void badUsage(Twine Error) { WithColor::error(errs(), ToolName) << Error << "\n"; printHelpMessage(); exit(1); } // Show the error message and exit. -LLVM_ATTRIBUTE_NORETURN static void fail(Twine Error) { +[[noreturn]] static void fail(Twine Error) { if (ParsingMRIScript) { WithColor::error(errs(), ToolName) << "script line " << MRILineNumber << ": " << Error << "\n"; diff --git a/llvm/tools/llvm-cvtres/llvm-cvtres.cpp b/llvm/tools/llvm-cvtres/llvm-cvtres.cpp index 24b3c6528240..0907c0a02f65 100644 --- a/llvm/tools/llvm-cvtres/llvm-cvtres.cpp +++ b/llvm/tools/llvm-cvtres/llvm-cvtres.cpp @@ -67,7 +67,7 @@ public: }; } -static LLVM_ATTRIBUTE_NORETURN void reportError(Twine Msg) { +[[noreturn]] static void reportError(Twine Msg) { errs() << Msg; exit(1); } diff --git a/llvm/tools/llvm-cxxdump/llvm-cxxdump.cpp b/llvm/tools/llvm-cxxdump/llvm-cxxdump.cpp index f214288e951b..4e1cca7d8ba3 100644 --- a/llvm/tools/llvm-cxxdump/llvm-cxxdump.cpp +++ b/llvm/tools/llvm-cxxdump/llvm-cxxdump.cpp @@ -49,7 +49,7 @@ static void error(std::error_code EC) { exit(1); } -LLVM_ATTRIBUTE_NORETURN static void error(Error Err) { +[[noreturn]] static void error(Error Err) { logAllUnhandledErrors(std::move(Err), WithColor::error(outs()), "reading file: "); outs().flush(); diff --git a/llvm/tools/llvm-ifs/ErrorCollector.cpp b/llvm/tools/llvm-ifs/ErrorCollector.cpp index 087a30c502c2..04daa848548e 100644 --- a/llvm/tools/llvm-ifs/ErrorCollector.cpp +++ b/llvm/tools/llvm-ifs/ErrorCollector.cpp @@ -57,7 +57,7 @@ ErrorCollector::~ErrorCollector() { } } -LLVM_ATTRIBUTE_NORETURN void ErrorCollector::fatalUnhandledError() { +[[noreturn]] void ErrorCollector::fatalUnhandledError() { errs() << "Program aborted due to unhandled Error(s):\n"; log(errs()); errs() << "\n"; diff --git a/llvm/tools/llvm-ifs/ErrorCollector.h b/llvm/tools/llvm-ifs/ErrorCollector.h index 67996f4b0052..7217ca3b859e 100644 --- a/llvm/tools/llvm-ifs/ErrorCollector.h +++ b/llvm/tools/llvm-ifs/ErrorCollector.h @@ -61,7 +61,7 @@ private: bool allErrorsHandled() const; /// Dump output and crash. - LLVM_ATTRIBUTE_NORETURN void fatalUnhandledError(); + [[noreturn]] void fatalUnhandledError(); bool ErrorsAreFatal; std::vector Errors; diff --git a/llvm/tools/llvm-lipo/llvm-lipo.cpp b/llvm/tools/llvm-lipo/llvm-lipo.cpp index d099ea1c2224..738f16ab64f6 100644 --- a/llvm/tools/llvm-lipo/llvm-lipo.cpp +++ b/llvm/tools/llvm-lipo/llvm-lipo.cpp @@ -36,13 +36,13 @@ using namespace llvm::object; static const StringRef ToolName = "llvm-lipo"; static LLVMContext LLVMCtx; -LLVM_ATTRIBUTE_NORETURN static void reportError(Twine Message) { +[[noreturn]] static void reportError(Twine Message) { WithColor::error(errs(), ToolName) << Message << "\n"; errs().flush(); exit(EXIT_FAILURE); } -LLVM_ATTRIBUTE_NORETURN static void reportError(Error E) { +[[noreturn]] static void reportError(Error E) { assert(E); std::string Buf; raw_string_ostream OS(Buf); @@ -51,7 +51,7 @@ LLVM_ATTRIBUTE_NORETURN static void reportError(Error E) { reportError(Buf); } -LLVM_ATTRIBUTE_NORETURN static void reportError(StringRef File, Error E) { +[[noreturn]] static void reportError(StringRef File, Error E) { assert(E); std::string Buf; raw_string_ostream OS(Buf); @@ -350,9 +350,9 @@ readInputBinaries(ArrayRef InputFiles) { return InputBinaries; } -LLVM_ATTRIBUTE_NORETURN -static void verifyArch(ArrayRef> InputBinaries, - ArrayRef VerifyArchList) { +[[noreturn]] static void +verifyArch(ArrayRef> InputBinaries, + ArrayRef VerifyArchList) { assert(!VerifyArchList.empty() && "The list of architectures should be non-empty"); assert(InputBinaries.size() == 1 && "Incorrect number of input binaries"); @@ -433,15 +433,15 @@ static void printBinaryArchs(const Binary *Binary, raw_ostream &OS) { OS << SliceOrErr->getArchString() << " \n"; } -LLVM_ATTRIBUTE_NORETURN -static void printArchs(ArrayRef> InputBinaries) { +[[noreturn]] static void +printArchs(ArrayRef> InputBinaries) { assert(InputBinaries.size() == 1 && "Incorrect number of input binaries"); printBinaryArchs(InputBinaries.front().getBinary(), outs()); exit(EXIT_SUCCESS); } -LLVM_ATTRIBUTE_NORETURN -static void printInfo(ArrayRef> InputBinaries) { +[[noreturn]] static void +printInfo(ArrayRef> InputBinaries) { // Group universal and thin files together for compatibility with cctools lipo for (auto &IB : InputBinaries) { const Binary *Binary = IB.getBinary(); @@ -463,9 +463,9 @@ static void printInfo(ArrayRef> InputBinaries) { exit(EXIT_SUCCESS); } -LLVM_ATTRIBUTE_NORETURN -static void thinSlice(ArrayRef> InputBinaries, - StringRef ArchType, StringRef OutputFileName) { +[[noreturn]] static void thinSlice(ArrayRef> InputBinaries, + StringRef ArchType, + StringRef OutputFileName) { assert(!ArchType.empty() && "The architecture type should be non-empty"); assert(InputBinaries.size() == 1 && "Incorrect number of input binaries"); assert(!OutputFileName.empty() && "Thin expects a single output file"); @@ -599,10 +599,10 @@ buildSlices(ArrayRef> InputBinaries, return Slices; } -LLVM_ATTRIBUTE_NORETURN -static void createUniversalBinary(ArrayRef> InputBinaries, - const StringMap &Alignments, - StringRef OutputFileName) { +[[noreturn]] static void +createUniversalBinary(ArrayRef> InputBinaries, + const StringMap &Alignments, + StringRef OutputFileName) { assert(InputBinaries.size() >= 1 && "Incorrect number of input binaries"); assert(!OutputFileName.empty() && "Create expects a single output file"); @@ -619,10 +619,10 @@ static void createUniversalBinary(ArrayRef> InputBinaries, exit(EXIT_SUCCESS); } -LLVM_ATTRIBUTE_NORETURN -static void extractSlice(ArrayRef> InputBinaries, - const StringMap &Alignments, - StringRef ArchType, StringRef OutputFileName) { +[[noreturn]] static void +extractSlice(ArrayRef> InputBinaries, + const StringMap &Alignments, StringRef ArchType, + StringRef OutputFileName) { assert(!ArchType.empty() && "The architecture type should be non-empty"); assert(InputBinaries.size() == 1 && "Incorrect number of input binaries"); @@ -678,11 +678,10 @@ buildReplacementSlices(ArrayRef> ReplacementBinaries, return Slices; } -LLVM_ATTRIBUTE_NORETURN -static void replaceSlices(ArrayRef> InputBinaries, - const StringMap &Alignments, - StringRef OutputFileName, - ArrayRef ReplacementFiles) { +[[noreturn]] static void +replaceSlices(ArrayRef> InputBinaries, + const StringMap &Alignments, + StringRef OutputFileName, ArrayRef ReplacementFiles) { assert(InputBinaries.size() == 1 && "Incorrect number of input binaries"); assert(!OutputFileName.empty() && "Replace expects a single output file"); diff --git a/llvm/tools/llvm-mt/llvm-mt.cpp b/llvm/tools/llvm-mt/llvm-mt.cpp index 6f26765331ba..1ff66ee8c1c5 100644 --- a/llvm/tools/llvm-mt/llvm-mt.cpp +++ b/llvm/tools/llvm-mt/llvm-mt.cpp @@ -64,7 +64,7 @@ public: }; } // namespace -LLVM_ATTRIBUTE_NORETURN static void reportError(Twine Msg) { +[[noreturn]] static void reportError(Twine Msg) { WithColor::error(errs(), "llvm-mt") << Msg << '\n'; exit(1); } diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index 48ae92f734c7..0e4f4024ca40 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -297,16 +297,15 @@ void objdump::reportWarning(const Twine &Message, StringRef File) { << "'" << File << "': " << Message << "\n"; } -LLVM_ATTRIBUTE_NORETURN void objdump::reportError(StringRef File, - const Twine &Message) { +[[noreturn]] void objdump::reportError(StringRef File, const Twine &Message) { outs().flush(); WithColor::error(errs(), ToolName) << "'" << File << "': " << Message << "\n"; exit(1); } -LLVM_ATTRIBUTE_NORETURN void objdump::reportError(Error E, StringRef FileName, - StringRef ArchiveName, - StringRef ArchitectureName) { +[[noreturn]] void objdump::reportError(Error E, StringRef FileName, + StringRef ArchiveName, + StringRef ArchitectureName) { assert(E); outs().flush(); WithColor::error(errs(), ToolName); @@ -325,7 +324,7 @@ static void reportCmdLineWarning(const Twine &Message) { WithColor::warning(errs(), ToolName) << Message << "\n"; } -LLVM_ATTRIBUTE_NORETURN static void reportCmdLineError(const Twine &Message) { +[[noreturn]] static void reportCmdLineError(const Twine &Message) { WithColor::error(errs(), ToolName) << Message << "\n"; exit(1); } diff --git a/llvm/tools/llvm-objdump/llvm-objdump.h b/llvm/tools/llvm-objdump/llvm-objdump.h index 33fb3f207f8e..3796878558de 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.h +++ b/llvm/tools/llvm-objdump/llvm-objdump.h @@ -139,10 +139,10 @@ void printSymbolTable(const object::ObjectFile *O, StringRef ArchiveName, void printSymbol(const object::ObjectFile *O, const object::SymbolRef &Symbol, StringRef FileName, StringRef ArchiveName, StringRef ArchitectureName, bool DumpDynamic); -LLVM_ATTRIBUTE_NORETURN void reportError(StringRef File, const Twine &Message); -LLVM_ATTRIBUTE_NORETURN void reportError(Error E, StringRef FileName, - StringRef ArchiveName = "", - StringRef ArchitectureName = ""); +[[noreturn]] void reportError(StringRef File, const Twine &Message); +[[noreturn]] void reportError(Error E, StringRef FileName, + StringRef ArchiveName = "", + StringRef ArchitectureName = ""); void reportWarning(const Twine &Message, StringRef File); template diff --git a/llvm/tools/llvm-profgen/ErrorHandling.h b/llvm/tools/llvm-profgen/ErrorHandling.h index 1d118c5f6e74..5d08c01ab4ce 100644 --- a/llvm/tools/llvm-profgen/ErrorHandling.h +++ b/llvm/tools/llvm-profgen/ErrorHandling.h @@ -18,9 +18,9 @@ using namespace llvm; -LLVM_ATTRIBUTE_NORETURN inline void -exitWithError(const Twine &Message, StringRef Whence = StringRef(), - StringRef Hint = StringRef()) { +[[noreturn]] inline void exitWithError(const Twine &Message, + StringRef Whence = StringRef(), + StringRef Hint = StringRef()) { WithColor::error(errs(), "llvm-profgen"); if (!Whence.empty()) errs() << Whence.str() << ": "; @@ -30,12 +30,12 @@ exitWithError(const Twine &Message, StringRef Whence = StringRef(), ::exit(EXIT_FAILURE); } -LLVM_ATTRIBUTE_NORETURN inline void -exitWithError(std::error_code EC, StringRef Whence = StringRef()) { +[[noreturn]] inline void exitWithError(std::error_code EC, + StringRef Whence = StringRef()) { exitWithError(EC.message(), Whence); } -LLVM_ATTRIBUTE_NORETURN inline void exitWithError(Error E, StringRef Whence) { +[[noreturn]] inline void exitWithError(Error E, StringRef Whence) { exitWithError(errorToErrorCode(std::move(E)), Whence); } diff --git a/llvm/tools/llvm-rc/llvm-rc.cpp b/llvm/tools/llvm-rc/llvm-rc.cpp index 0f70e30b2b38..c7c93ae485d8 100644 --- a/llvm/tools/llvm-rc/llvm-rc.cpp +++ b/llvm/tools/llvm-rc/llvm-rc.cpp @@ -111,7 +111,7 @@ static ExitOnError ExitOnErr; static FileRemover TempPreprocFile; static FileRemover TempResFile; -LLVM_ATTRIBUTE_NORETURN static void fatalError(const Twine &Message) { +[[noreturn]] static void fatalError(const Twine &Message) { errs() << Message << "\n"; exit(1); } diff --git a/llvm/tools/llvm-readobj/llvm-readobj.cpp b/llvm/tools/llvm-readobj/llvm-readobj.cpp index 0b49f03f4275..76ac5be8c826 100644 --- a/llvm/tools/llvm-readobj/llvm-readobj.cpp +++ b/llvm/tools/llvm-readobj/llvm-readobj.cpp @@ -157,7 +157,7 @@ static StringRef ToolName; namespace llvm { -LLVM_ATTRIBUTE_NORETURN static void error(Twine Msg) { +[[noreturn]] static void error(Twine Msg) { // Flush the standard output to print the error at a // proper place. fouts().flush(); @@ -165,7 +165,7 @@ LLVM_ATTRIBUTE_NORETURN static void error(Twine Msg) { exit(1); } -LLVM_ATTRIBUTE_NORETURN void reportError(Error Err, StringRef Input) { +[[noreturn]] void reportError(Error Err, StringRef Input) { assert(Err); if (Input == "-") Input = ""; diff --git a/llvm/tools/llvm-readobj/llvm-readobj.h b/llvm/tools/llvm-readobj/llvm-readobj.h index 43d19b4d3f5c..7672da5c0aae 100644 --- a/llvm/tools/llvm-readobj/llvm-readobj.h +++ b/llvm/tools/llvm-readobj/llvm-readobj.h @@ -21,7 +21,7 @@ namespace llvm { } // Various helper functions. - LLVM_ATTRIBUTE_NORETURN void reportError(Error Err, StringRef Input); + [[noreturn]] void reportError(Error Err, StringRef Input); void reportWarning(Error Err, StringRef Input); template T unwrapOrError(StringRef Input, Expected EO) { diff --git a/llvm/tools/llvm-strings/llvm-strings.cpp b/llvm/tools/llvm-strings/llvm-strings.cpp index 0b068749917b..e7c50f89d51b 100644 --- a/llvm/tools/llvm-strings/llvm-strings.cpp +++ b/llvm/tools/llvm-strings/llvm-strings.cpp @@ -73,7 +73,7 @@ static bool PrintFileName; enum radix { none, octal, hexadecimal, decimal }; static radix Radix; -LLVM_ATTRIBUTE_NORETURN static void reportCmdLineError(const Twine &Message) { +[[noreturn]] static void reportCmdLineError(const Twine &Message) { WithColor::error(errs(), ToolName) << Message << "\n"; exit(1); } diff --git a/llvm/tools/split-file/split-file.cpp b/llvm/tools/split-file/split-file.cpp index 3ebbda47e0d5..355678433ac1 100644 --- a/llvm/tools/split-file/split-file.cpp +++ b/llvm/tools/split-file/split-file.cpp @@ -42,8 +42,7 @@ static cl::opt noLeadingLines("no-leading-lines", static StringRef toolName; static int errorCount; -LLVM_ATTRIBUTE_NORETURN static void fatal(StringRef filename, - const Twine &message) { +[[noreturn]] static void fatal(StringRef filename, const Twine &message) { if (filename.empty()) WithColor::error(errs(), toolName) << message << '\n'; else