Skip to content

Commit 07da452

Browse files
committed
build: check and add -fsized-deallocation
We use C++17 for the Swift compiler and IRGen uses the sized deallocation for releasing memory it creates with over-allocation. That triggers ASAN warnings due to the mismatched `operator new`/`operator delete`.
1 parent 663ec93 commit 07da452

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,19 @@ if(CMAKE_C_COMPILER_ID MATCHES Clang)
834834
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Werror=c++98-compat-extra-semi>)
835835
endif()
836836

837+
if(CMAKE_CXX_COMPILER_ID MATCHES Clang)
838+
include(CheckCXXCompilerFlag)
839+
# Check for '-fsized-deallocation', which we need in IRGen. Clang presumably
840+
# adds this flag as a requirement for C++14+ to avoid a potential source
841+
# compatibility issue with C++11 where the 2-parameter `operator delete` was
842+
# used for placement deletion.
843+
check_cxx_compiler_flag("-fsized-deallocation"
844+
CXX_SUPPORTS_FSIZED_DEALLOCATION)
845+
if(CXX_SUPPORTS_FSIZED_DEALLOCATION)
846+
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fsized-deallocation>)
847+
endif()
848+
endif()
849+
837850
option(SWIFT_BUILD_SWIFT_SYNTAX
838851
"Enable building swift syntax"
839852
FALSE)

lib/IRGen/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ add_swift_host_library(swiftIRGen STATIC
7676
transformutils
7777
irprinter
7878
)
79-
target_compile_options(swiftIRGen PRIVATE
80-
$<$<AND:$<PLATFORM_ID:Linux>,$<CXX_COMPILER_ID:Clang>>:-fsized-deallocation>)
8179
target_link_libraries(swiftIRGen INTERFACE
8280
clangCodeGen
8381
clangAST)

0 commit comments

Comments
 (0)