From dffd6036e09a3aad653ab10d9f718ec2f1db64ca Mon Sep 17 00:00:00 2001 From: Frank Lichtenheld Date: Tue, 14 Nov 2023 17:40:31 +0100 Subject: [PATCH] RC: suppress compiler warnings with GCC 12 and 13 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We're pretty sure that these warnings are false positives. Both are related to destructing MultiCompleteType objects. GCC 12 (thread_unsafe_refcount): rc.hpp:322:18: pointer used after ‘void operator delete(void*, std::size_t)’ [-Wuse-after-free] GCC 13 (thread_safe_refcount, only arm64): inlined from ‘...thread_safe_refcount::operator--()’ at .../rc.hpp:404:39 atomic_base.h:645:34: ‘long unsigned int __atomic_sub_fetch_8(...)’ writing 8 bytes into a region of size 0 overflows the destination [-Werror=stringop-overflow=] Signed-off-by: Frank Lichtenheld --- openvpn/common/rc.hpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/openvpn/common/rc.hpp b/openvpn/common/rc.hpp index c0cf912c..17c6eb7a 100644 --- a/openvpn/common/rc.hpp +++ b/openvpn/common/rc.hpp @@ -304,6 +304,26 @@ class RCWeakPtr typename T::Controller::Ptr controller; }; +/* We're pretty sure these are false positives. They only occur with very + specific compiler versions and/or architectures. + + For some reason some gcc versions think that the reference counter goes + away too soon when destructing certain MultiCompleteType objects. The + warnings/errors do not tell us why they think that. + + So for now we display the warnings, but do not fail -Werror builds over + them. So that we can fail them for any other new warnings. + */ +#if !defined(__clang__) && defined(__GNUC__) +#pragma GCC diagnostic push +#if __GNUC__ == 12 +#pragma GCC diagnostic warning "-Wuse-after-free" +#endif +#if __GNUC__ == 13 +#pragma GCC diagnostic warning "-Wstringop-overflow" +#endif +#endif + class thread_unsafe_refcount { public: @@ -479,6 +499,10 @@ class thread_safe_refcount std::atomic rc; }; +#if !defined(__clang__) && defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + // Reference count base class for objects tracked by RCPtr. // Disallows copying and assignment. template // RCImpl = thread_safe_refcount or thread_unsafe_refcount