Skip to content

Commit c93fe4f

Browse files
committed
Add ASAN to fortran projects compiled wwith flang
1 parent 51e83db commit c93fe4f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

cmake/therock_sanitizers.cmake

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ function(therock_sanitizer_configure
3232
# TODO: Support ASAN_STATIC to use static ASAN linkage. Shared is almost always the right thing,
3333
# so make "ASAN" imply shared linkage.
3434
string(APPEND _stanza "string(APPEND CMAKE_CXX_FLAGS \" -fsanitize=address -fno-omit-frame-pointer -g\")\n")
35+
36+
set(_fortran_and_flang_check "$<AND:$<COMPILE_LANGUAGE:Fortran>,$<Fortran_COMPILER_ID:Flang>>")
37+
string(APPEND _stanza "add_compile_options($<${_fortran_and_flang_check}>:-fsanitize=address -fno-omit-frame-pointer -g>)\n")
38+
3539
# Sharp edge: The -shared-libsan flag is compiler frontend specific:
3640
# gcc (and gfortran): defaults to shared sanitizer linkage
3741
# clang: defaults to static linkage and requires -shared-libsan to link shared
@@ -40,8 +44,8 @@ function(therock_sanitizer_configure
4044
# Only enable ASAN for C/C++ for now. Include fortran once the toolchain
4145
# is available and can be used for portable builds.
4246
# https://github.com/ROCm/TheRock/issues/1782
43-
string(APPEND _stanza "add_link_options($<$<LINK_LANGUAGE:C,CXX>:-fsanitize=address>\n")
44-
string(APPEND _stanza " $<$<AND:$<LINK_LANGUAGE:C,CXX>,$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>>:-shared-libsan>)\n")
47+
string(APPEND _stanza "add_link_options($<$<OR:$<LINK_LANGUAGE:C,CXX>,$<${_fortran_and_flang_check}>>:-fsanitize=address>\n")
48+
string(APPEND _stanza " $<$<OR:$<AND:$<LINK_LANGUAGE:C,CXX>,$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>>,$<${_fortran_and_flang_check}>>:-shared-libsan>)\n")
4549
# Filter GPU_TARGETS to enable xnack+ mode only for gfx targets that support it.
4650
string(APPEND _stanza "list(TRANSFORM GPU_TARGETS REPLACE \"^(gfx942|gfx950)$\" \"\\\\1:xnack+\")\n")
4751
string(APPEND _stanza "set(AMDGPU_TARGETS \"\${GPU_TARGETS}\")\n")

0 commit comments

Comments
 (0)