Commit 6d874f05 by Nicolas Capens Committed by Nicolas Capens

Selectively suppress class-memaccess warning/error

To still produce the class-memaccess diagnostic on unintended cases, suppress it only for our Memset<T> case and LLVM. Bug: b/135744933 Change-Id: Id3b421a3b831600097d198ac793f582467d0a520 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/33429 Presubmit-Ready: Nicolas Capens <nicolascapens@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarBen Clayton <bclayton@google.com>
parent 522d5121
...@@ -339,15 +339,6 @@ else() ...@@ -339,15 +339,6 @@ else()
"-Wmissing-braces" "-Wmissing-braces"
) )
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8)
list(APPEND SWIFTSHADER_COMPILE_OPTIONS
# Warnings that should not be treated as errors:
"-Wno-error=class-memaccess" # TODO(b/134932616): Reliably initializing cache keys currently requires memset().
)
endif()
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
list(APPEND SWIFTSHADER_COMPILE_OPTIONS list(APPEND SWIFTSHADER_COMPILE_OPTIONS
"-Wunused-lambda-capture" "-Wunused-lambda-capture"
...@@ -1417,6 +1408,11 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") ...@@ -1417,6 +1408,11 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
"-Wno-maybe-uninitialized" # ‘X’ may be used uninitialized in this function "-Wno-maybe-uninitialized" # ‘X’ may be used uninitialized in this function
"-Wno-unused-but-set-variable" # variable ‘X’ set but not used "-Wno-unused-but-set-variable" # variable ‘X’ set but not used
) )
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8)
list(APPEND LLVM_COMPILE_OPTIONS
"-Wno-class-memaccess" # memset/memcmp used on non-trivial class object
)
endif()
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
list(APPEND LLVM_COMPILE_OPTIONS list(APPEND LLVM_COMPILE_OPTIONS
"/wd4141" # 'inline': used more than once "/wd4141" # 'inline': used more than once
......
...@@ -55,7 +55,21 @@ namespace sw ...@@ -55,7 +55,21 @@ namespace sw
Memset(T *object, int val) Memset(T *object, int val)
{ {
static_assert(std::is_base_of<Memset<T>, T>::value, "Memset<T> must only clear the memory of a type of which it is a base class"); static_assert(std::is_base_of<Memset<T>, T>::value, "Memset<T> must only clear the memory of a type of which it is a base class");
// GCC 8+ warns that
// "‘void* memset(void*, int, size_t)’ clearing an object of non-trivial type ‘T’;
// use assignment or value-initialization instead [-Werror=class-memaccess]"
// This is benign iff it happens before any of the base or member constructrs are called.
#if defined(__GNUC__) && (__GNUC__ >= 8)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wclass-memaccess"
#endif
memset(object, 0, sizeof(T)); memset(object, 0, sizeof(T));
#if defined(__GNUC__) && (__GNUC__ >= 8)
#pragma GCC diagnostic pop
#endif
} }
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment