From dc2a8c509507dffa28e4c356418207e9b9bb0ca5 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Wed, 17 Feb 2021 08:21:50 +0100 Subject: More targeted suppression of bogus GCC -Werror=stringop-overflow= ...given that "[8/9/10/11 Regression] -Wstringop-overflow false positive due to using MEM_REF type of &MEM" is declared fixed now on GCC 11 trunk. (Moving -Wno-stringop-overflow from gb_CFLAGS_WERROR to gb_CXXFLAGS_COMMON is done for no other reason than to harmonize this with the code for the similar HAVE_BROKEN_GCC_WMAYBE_UNINITIALIZED.) Change-Id: I3468138c9bbda28f754d4162cb9c059796bd3932 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111029 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- config_host.mk.in | 1 + configure.ac | 49 ++++++++++++++++++++++++++++++++++ solenv/gbuild/platform/com_GCC_defs.mk | 7 ++--- 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/config_host.mk.in b/config_host.mk.in index d6edba704b21..f0bf804474f7 100644 --- a/config_host.mk.in +++ b/config_host.mk.in @@ -261,6 +261,7 @@ export GTK3_LIBS=$(gb_SPACE)@GTK3_LIBS@ export USING_X11=@USING_X11@ export HAMCREST_JAR=@HAMCREST_JAR@ export HAVE_BROKEN_GCC_WMAYBE_UNINITIALIZED=@HAVE_BROKEN_GCC_WMAYBE_UNINITIALIZED@ +export HAVE_BROKEN_GCC_WSTRINGOP_OVERFLOW=@HAVE_BROKEN_GCC_WSTRINGOP_OVERFLOW@ export HAVE_CLANG_DEBUG_INFO_KIND_CONSTRUCTOR=@HAVE_CLANG_DEBUG_INFO_KIND_CONSTRUCTOR@ export HAVE_LO_CLANG_DLLEXPORTINLINES=@HAVE_LO_CLANG_DLLEXPORTINLINES@ export HAVE_GCC_AVX=@HAVE_GCC_AVX@ diff --git a/configure.ac b/configure.ac index 38953def3252..d96bc28576be 100644 --- a/configure.ac +++ b/configure.ac @@ -7379,6 +7379,55 @@ if test "$GCC" = yes && test "$COM_IS_CLANG" != TRUE; then fi AC_SUBST([HAVE_BROKEN_GCC_WMAYBE_UNINITIALIZED]) +dnl Check for "[8/9/10/11 Regression] +dnl -Wstringop-overflow false positive due to using MEM_REF type of &MEM" (fixed in GCC 11), which +dnl hits us e.g. with GCC 10 and --enable-optimized at +dnl +dnl In file included from include/rtl/string.hxx:49, +dnl from include/rtl/ustring.hxx:43, +dnl from include/osl/file.hxx:35, +dnl from include/codemaker/global.hxx:28, +dnl from include/codemaker/options.hxx:23, +dnl from codemaker/source/commoncpp/commoncpp.cxx:24: +dnl In function ‘char* rtl::addDataHelper(char*, const char*, std::size_t)’, +dnl inlined from ‘static char* rtl::ToStringHelper::addData(char*, const char*) [with long unsigned int N = 3]’ at include/rtl/stringconcat.hxx:147:85, +dnl inlined from ‘char* rtl::OStringConcat::addData(char*) const [with T1 = const char [3]; T2 = rtl::OString]’ at include/rtl/stringconcat.hxx:226:103, +dnl inlined from ‘rtl::OStringBuffer& rtl::OStringBuffer::append(rtl::OStringConcat&&) [with T1 = const char [3]; T2 = rtl::OString]’ at include/rtl/strbuf.hxx:599:30, +dnl inlined from ‘rtl::OString codemaker::cpp::scopedCppName(const rtl::OString&, bool)’ at codemaker/source/commoncpp/commoncpp.cxx:53:55: +dnl include/rtl/stringconcat.hxx:78:15: error: writing 2 bytes into a region of size 1 [-Werror=stringop-overflow=] +dnl 78 | memcpy( buffer, data, length ); +dnl | ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~ +HAVE_BROKEN_GCC_WSTRINGOP_OVERFLOW= +if test "$GCC" = yes && test "$COM_IS_CLANG" != TRUE; then + AC_MSG_CHECKING([whether $CXX_BASE might report false -Werror=stringop-overflow=]) + AC_LANG_PUSH([C++]) + save_CXXFLAGS=$CXXFLAGS + CXXFLAGS="$CXXFLAGS $CXXFLAGS_CXX11 -Werror -Wstringop-overflow" + if test "$ENABLE_OPTIMIZED" = TRUE; then + CXXFLAGS="$CXXFLAGS -O2" + else + CXXFLAGS="$CXXFLAGS -O0" + fi + dnl Test code taken from : + AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ + void fill(char const * begin, char const * end, char c); + struct q { + char ids[4]; + char username[6]; + }; + void test(q & c) { + fill(c.ids, c.ids + sizeof(c.ids), '\0'); + __builtin_strncpy(c.username, "root", sizeof(c.username)); + } + ]])], [AC_MSG_RESULT([no])], [ + HAVE_BROKEN_GCC_WSTRINGOP_OVERFLOW=TRUE + AC_MSG_RESULT([yes]) + ]) + CXXFLAGS=$save_CXXFLAGS + AC_LANG_POP([C++]) +fi +AC_SUBST([HAVE_BROKEN_GCC_WSTRINGOP_OVERFLOW]) + dnl =================================================================== dnl CPU Intrinsics support - SSE, AVX dnl =================================================================== diff --git a/solenv/gbuild/platform/com_GCC_defs.mk b/solenv/gbuild/platform/com_GCC_defs.mk index 23a113cbca2f..9b7e6f739552 100644 --- a/solenv/gbuild/platform/com_GCC_defs.mk +++ b/solenv/gbuild/platform/com_GCC_defs.mk @@ -93,6 +93,10 @@ ifeq ($(HAVE_BROKEN_GCC_WMAYBE_UNINITIALIZED),TRUE) gb_CXXFLAGS_COMMON += -Wno-maybe-uninitialized endif +ifeq ($(HAVE_BROKEN_GCC_WSTRINGOP_OVERFLOW),TRUE) +gb_CXXFLAGS_COMMON += -Wno-stringop-overflow +endif + gb_CXXFLAGS_Wundef = -Wno-undef ifeq ($(strip $(gb_GCOV)),YES) @@ -158,9 +162,6 @@ endif endif gb_CFLAGS_WERROR = $(if $(ENABLE_WERROR),-Werror) -ifeq ($(ENABLE_OPTIMIZED)-$(COM_IS_CLANG),TRUE-) -gb_CFLAGS_WERROR += -Wno-stringop-overflow -endif # This is the default in non-C++11 mode ifeq ($(COM_IS_CLANG),TRUE) -- cgit