aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRadu Hociung <radu.git@ohmi.org>2023-01-09 13:04:58 -0500
committerRadu Hociung <radu.git@ohmi.org>2023-01-09 13:07:01 -0500
commitb71cae3d2f698d0990f7c96cc63e6f5fceed1a81 (patch)
treeaca8aeefd6a18b93e0186e37c145b3fcc93dc7e5
parented517e9abefca36d55928fdbde0dd844d11fadb8 (diff)
downloadprotobuf-b71cae3d2f698d0990f7c96cc63e6f5fceed1a81.tar.gz
Add explicit abort() at the end of AlignFail
GCC cannot infer that `LogMessage::Finish()` (called indirectly by `GOOGLE_LOG(FAIL)` in `AlignFail`) exits program when `level_ == LOGLEVEL_FATAL`. Compilation will create a warning in projects importing the library for debug builds. The attribute cannot be individually assigned to `LogMessage::Finish()` because it does return conditionally of the log level. Tried with GCC 9.3.0 and GCC 12.1.0. This change adds an explicit abort() for compiler to clearly understand this does not return, and enables `[[noreturn]]` for MSVC as well.
-rw-r--r--src/google/protobuf/generated_message_tctable_impl.h4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/google/protobuf/generated_message_tctable_impl.h b/src/google/protobuf/generated_message_tctable_impl.h
index 3f2b1cabd..5d698f776 100644
--- a/src/google/protobuf/generated_message_tctable_impl.h
+++ b/src/google/protobuf/generated_message_tctable_impl.h
@@ -32,6 +32,7 @@
#define GOOGLE_PROTOBUF_GENERATED_MESSAGE_TCTABLE_IMPL_H__
#include <cstdint>
+#include <cstdlib>
#include <type_traits>
#include <google/protobuf/parse_context.h>
@@ -100,6 +101,9 @@ template <size_t align>
#endif
void AlignFail(uintptr_t address) {
GOOGLE_LOG(FATAL) << "Unaligned (" << align << ") access at " << address;
+ // This abort() is unreachable; it is only here to silence compiler warnings
+ // that do not know that FATAL always terminates the program.
+ abort();
}
extern template void AlignFail<4>(uintptr_t);