diff --git a/src/hotspot/share/compiler/methodMatcher.cpp b/src/hotspot/share/compiler/methodMatcher.cpp index 1a0ade2fadb..ace9ab2dd28 100644 --- a/src/hotspot/share/compiler/methodMatcher.cpp +++ b/src/hotspot/share/compiler/methodMatcher.cpp @@ -224,7 +224,11 @@ static MethodMatcher::Mode check_mode(char name[], const char*& error_msg) { return MethodMatcher::Any; } match |= MethodMatcher::Suffix; - memmove(name, name + 1, strlen(name + 1) + 1); +PRAGMA_DIAG_PUSH +PRAGMA_STRINGOP_OVERREAD_IGNORED + // This code can incorrectly cause a "stringop-overread" warning with gcc + memmove(name, name + 1, strlen(name + 1) + 1); +PRAGMA_DIAG_POP } size_t len = strlen(name); diff --git a/src/hotspot/share/utilities/compilerWarnings.hpp b/src/hotspot/share/utilities/compilerWarnings.hpp index ddcaf022fa6..e00286723b5 100644 --- a/src/hotspot/share/utilities/compilerWarnings.hpp +++ b/src/hotspot/share/utilities/compilerWarnings.hpp @@ -74,6 +74,10 @@ #define PRAGMA_STRINGOP_OVERFLOW_IGNORED #endif +#ifndef PRAGMA_STRINGOP_OVERREAD_IGNORED +#define PRAGMA_STRINGOP_OVERREAD_IGNORED +#endif + #ifndef PRAGMA_INFINITE_RECURSION_IGNORED #define PRAGMA_INFINITE_RECURSION_IGNORED #endif diff --git a/src/hotspot/share/utilities/compilerWarnings_gcc.hpp b/src/hotspot/share/utilities/compilerWarnings_gcc.hpp index 1dd5892e4c3..4366cde6bd8 100644 --- a/src/hotspot/share/utilities/compilerWarnings_gcc.hpp +++ b/src/hotspot/share/utilities/compilerWarnings_gcc.hpp @@ -65,6 +65,12 @@ #define PRAGMA_STRINGOP_OVERFLOW_IGNORED PRAGMA_DISABLE_GCC_WARNING("-Wstringop-overflow") #endif +// Disable -Wstringop-overread which is introduced in GCC 11. +// https://gcc.gnu.org/gcc-11/changes.html +#if !defined(__clang_major__) && (__GNUC__ >= 11) +#define PRAGMA_STRINGOP_OVERREAD_IGNORED PRAGMA_DISABLE_GCC_WARNING("-Wstringop-overread") +#endif + #define PRAGMA_NONNULL_IGNORED PRAGMA_DISABLE_GCC_WARNING("-Wnonnull") #define PRAGMA_ZERO_AS_NULL_POINTER_CONSTANT_IGNORED \