Skip to content

Commit 88c9d6b

Browse files
authored
Suppress some GCC false-positive warnings (#896)
1 parent 3d2164a commit 88c9d6b

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
- Fixed thread-local context duplication across shared libraries ([#890](https://github.com/odygrd/quill/issues/890))
102102
- Added a `nullptr` check in macro-free log functions (`LogFunctions.h`) to allow calls with an uninitialized logger.
103103
Macro-based logging remains deliberately unchanged ([#894](https://github.com/odygrd/quill/issues/894))
104+
- Suppress GCC false-positive warnings during LTO builds.
104105

105106
## v11.0.2
106107

include/quill/core/Codec.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ QUILL_NODISCARD inline size_t safe_strnlen(char const* str, size_t maxlen) noexc
9999
#if __GNUC__ >= 13
100100
#pragma GCC diagnostic ignored "-Wstringop-overread"
101101
#endif
102+
103+
// Suppress during LTO analysis
104+
asm volatile("" : "+r"(maxlen) : : "memory");
102105
#endif
103106

104107
auto end = static_cast<char const*>(std::memchr(str, '\0', maxlen));

include/quill/core/LoggerBase.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,15 @@ class LoggerBase
117117
*/
118118
QUILL_NODISCARD LogLevel get_log_level() const noexcept
119119
{
120-
return _log_level.load(std::memory_order_relaxed);
120+
auto const* self = this;
121+
122+
#if defined(__GNUC__) && !defined(__clang__)
123+
// GCC warns about potential null pointer access when logger might be
124+
// uninitialized during LTO analysis
125+
asm volatile("" : "+r"(self) : : "memory");
126+
#endif
127+
128+
return self->_log_level.load(std::memory_order_relaxed);
121129
}
122130

123131
/**

0 commit comments

Comments
 (0)