Merge pull request #170 from microsoft/gcc-warning

Addressing #168
This commit is contained in:
Matthew Parkinson
2020-04-13 08:49:21 +01:00
committed by GitHub
2 changed files with 14 additions and 0 deletions

View File

@@ -33,6 +33,14 @@ macro(warnings_high)
add_compile_options(-Wsign-conversion)
endif ()
add_compile_options(-Wall -Wextra -Werror -Wundef)
# There are a few places with subtle reasons for array access being correct
# GCC's warnings are too aggressive and incorrectly assume the code is wrong.
# Disabling only in Release is so the ASSUME can be mapped to assert and check
# at runtime in debug. This ensures we are covering the cases of concern with
# debug checks, but not incurring runtime penalties in release.
if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND (CMAKE_BUILD_TYPE STREQUAL "Release"))
add_compile_options(-Wno-array-bounds)
endif ()
endif()
endmacro()

View File

@@ -62,6 +62,12 @@ namespace snmalloc
#else
# if __has_builtin(__builtin_assume)
# define SNMALLOC_ASSUME(x) __builtin_assume((x))
# elif defined(_MSC_VER)
# define SNMALLOC_ASSUME(x) __assume((x));
# elif defined(__GNUC__)
# define SNMALLOC_ASSUME(x) \
if (!(x)) \
__builtin_unreachable();
# else
# define SNMALLOC_ASSUME(x) \
do \