Skip to content

Commit 6074e6e

Browse files
author
Christian Convey
committed
[logging] LOG(FATAL) calls [[noreturn]] functions
Ensure that `LOG(FATAL)` always resolves to calling `[[noreturn]]` code. This has two benefits: - Helps developers more quickly understand the intended/required behavior for `LOG(FATAL)` calls. - May eliminate spurious compiler warnings based on control-flow analysis. E.g. gcc's / clang's `-Wno-return` warnings.
1 parent fa834f6 commit 6074e6e

File tree

6 files changed

+8
-7
lines changed

6 files changed

+8
-7
lines changed

apps/android_camera/app/src/main/jni/tvm_runtime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ namespace tvm {
7474
namespace runtime {
7575
namespace detail {
7676
// Override logging mechanism
77-
void LogFatalImpl(const std::string& file, int lineno, const std::string& message) {
77+
[[noreturn]] void LogFatalImpl(const std::string& file, int lineno, const std::string& message) {
7878
std::string m = file + ":" + std::to_string(lineno) + ": " + message;
7979
__android_log_write(ANDROID_LOG_DEBUG, "TVM_RUNTIME", m.c_str());
8080
throw InternalError(file, lineno, message);

apps/android_rpc/app/src/main/jni/tvm_runtime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ namespace tvm {
9292
namespace runtime {
9393
namespace detail {
9494
// Override logging mechanism
95-
void LogFatalImpl(const std::string& file, int lineno, const std::string& message) {
95+
[[noreturn]] void LogFatalImpl(const std::string& file, int lineno, const std::string& message) {
9696
std::string m = file + ":" + std::to_string(lineno) + ": " + message;
9797
__android_log_write(ANDROID_LOG_DEBUG, "TVM_RUNTIME", m.c_str());
9898
throw InternalError(file, lineno, message);

apps/ios_rpc/tvmrpc/TVMRuntime.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
namespace detail {
4242

4343
// Override logging mechanism
44-
void LogFatalImpl(const std::string& file, int lineno, const std::string& message) {
44+
[[noreturn]] void LogFatalImpl(const std::string& file, int lineno, const std::string& message) {
4545
throw tvm::runtime::InternalError(file, lineno, message);
4646
}
4747

include/tvm/runtime/logging.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ namespace detail {
286286
*
287287
* \sa TVM_LOG_CUSTOMIZE
288288
*/
289-
TVM_DLL void LogFatalImpl(const std::string& file, int lineno, const std::string& message);
289+
[[noreturn]] TVM_DLL void LogFatalImpl(const std::string& file, int lineno,
290+
const std::string& message);
290291

291292
/*!
292293
* \brief Custom implementations of LogMessage.
@@ -306,7 +307,7 @@ class LogFatal {
306307
#pragma disagnostic push
307308
#pragma warning(disable : 4722)
308309
#endif
309-
~LogFatal() TVM_THROW_EXCEPTION { LogFatalImpl(file_, lineno_, stream_.str()); }
310+
[[noreturn]] ~LogFatal() TVM_THROW_EXCEPTION { LogFatalImpl(file_, lineno_, stream_.str()); }
310311
#ifdef _MSC_VER
311312
#pragma disagnostic pop
312313
#endif

src/runtime/hexagon/hexagon_common.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void HexagonLog(const std::string& file, int lineno, const std::string& message)
8484
} // namespace
8585

8686
namespace detail {
87-
void LogFatalImpl(const std::string& file, int lineno, const std::string& message) {
87+
[[noreturn]] void LogFatalImpl(const std::string& file, int lineno, const std::string& message) {
8888
HexagonLog(file, lineno, message);
8989
throw InternalError(file, lineno, message);
9090
}

web/emcc/wasm_runtime.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ namespace tvm {
6868
namespace runtime {
6969
namespace detail {
7070
// Override logging mechanism
71-
void LogFatalImpl(const std::string& file, int lineno, const std::string& message) {
71+
[[noreturn]] void LogFatalImpl(const std::string& file, int lineno, const std::string& message) {
7272
std::cerr << "[FATAL] " << file << ":" << lineno << ": " << message << std::endl;
7373
abort();
7474
}

0 commit comments

Comments
 (0)