Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Allow non-strict aliasing and overflow optimizations #1752

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cmake/common/compiler_common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ set(CMAKE_VISIBILITY_INLINES_HIDDEN TRUE)
# clang options for C, C++, ObjC, and ObjC++
set(
_ares_clang_common_options
-fno-strict-aliasing
-Wblock-capture-autoreleasing
# -Wswitch
-Wdeprecated
Expand Down Expand Up @@ -99,6 +100,12 @@ set(
-Wno-delete-non-abstract-non-virtual-dtor
)

set(
_ares_gcc_common_options
-fwrapv
-fno-strict-aliasing
)

if(NOT DEFINED CMAKE_COMPILE_WARNING_AS_ERROR)
set(CMAKE_COMPILE_WARNING_AS_ERROR OFF)
endif()
5 changes: 5 additions & 0 deletions cmake/linux/compilerconfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options(
"$<$<COMPILE_LANGUAGE:C>:${_ares_clang_c_options}>"
"$<$<COMPILE_LANGUAGE:CXX>:${_ares_clang_cxx_options}>"
-fwrapv
)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(
${_ares_gcc_common_options}
)
endif()
1 change: 1 addition & 0 deletions cmake/macos/compilerconfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ if(NOT XCODE)
add_compile_options(
"$<$<COMPILE_LANGUAGE:C>:${_ares_clang_c_options}>"
"$<$<COMPILE_LANGUAGE:CXX>:${_ares_clang_cxx_options}>"
-fwrapv
-mmacos-version-min=10.13
)
endif()
1 change: 1 addition & 0 deletions cmake/macos/xcode.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNUSED_VALUE YES)
set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNUSED_VARIABLE NO) # todo
set(CMAKE_XCODE_ATTRIBUTE_GCC_NO_COMMON_BLOCKS YES)
set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_64_TO_32_BIT_CONVERSION NO) # todo
set(CMAKE_XCODE_ATTRIBUTE_GCC_STRICT_ALIASING NO)

set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS NO)
set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_SHADOW NO)
Expand Down
15 changes: 13 additions & 2 deletions cmake/windows/compilerconfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,21 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
"$<$<COMPILE_LANGUAGE:C,CXX>:${_ares_clang_cl_c_cxx_options}>"
)
if(NOT MSVC)
# statically link libstdc++ if compiling under msys2/mingw
# we are on msys2 clang
# statically link libc++
add_link_options(-static-libstdc++)
# msys2/mingw-specific invocations to make clang emit debug symbols
set(_ares_mingw_clang_debug_compile_options -g -gcodeview)
set(_ares_mingw_clang_debug_link_options -fuse-ld=lld -g -Wl,--pdb=)
add_compile_options("$<$<CONFIG:Debug,RelWithDebInfo>:${_ares_mingw_clang_debug_compile_options}>")
add_link_options("$<$<CONFIG:Debug,RelWithDebInfo>:${_ares_mingw_clang_debug_link_options}>")
# clang-cl does not understand -fwrapv, but we do want it on msys2 clang
add_compile_options(-fwrapv)
else()
# generate PDBs rather than embed debug symbols
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT ProgramDatabase)
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:${_ares_msvc_cxx_options}>")
# kill
# work around https://gitlab.kitware.com/cmake/cmake/-/issues/26559
add_compile_options($<$<AND:$<BOOL:${ENABLE_IPO}>,$<NOT:$<CONFIG:Debug>>>:-flto=thin>)
add_link_options(
$<$<AND:$<BOOL:${ENABLE_IPO}>,$<NOT:$<CONFIG:Debug>>>:-flto=thin>
Expand All @@ -99,6 +102,10 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
$<$<NOT:$<CONFIG:Debug>>:/OPT:REF>
$<$<NOT:$<CONFIG:Debug>>:/OPT:ICF>
)
# add -fwrapv
add_compile_options(
"$<$<COMPILE_LANGUAGE:C,CXX>:/clang:-fwrapv>"
)
endif()

# optimizations
Expand All @@ -114,6 +121,10 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
if(CMAKE_COMPILE_WARNING_AS_ERROR)
add_link_options(/WX)
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(
${_ares_gcc_common_options}
)
endif()

if(NOT MINGW)
Expand Down
Loading