Skip to content

Commit 4582a90

Browse files
author
Tor Didriksen
committed
Bug#27095089 ENABLE -FSANITIZE-ADDRESS-USE-AFTER-SCOPE BY DEFAULT FOR ASAN BUILDS
See bug 24343330, which needs -fsanitize=address -fsanitize-address-use-after-scope in order to be detected Add a compiler feature check for -fsanitize=address -fsanitize-address-use-after-scope and enable it if supported for 'cmake -DWITH_ASAN=1' *and* the extra -DWITH_ASAN_SCOPE=1 is enabled. Change-Id: I25100a03c47de74df235360d57297e60c2352b88 (cherry picked from commit e15249418502f61437fa24b9641e9879ba4d3a66)
1 parent acad90d commit 4582a90

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,25 @@ MACRO(MY_SANITIZER_CHECK SAN_OPT RESULT)
300300
ENDMACRO()
301301

302302
OPTION(WITH_ASAN "Enable address sanitizer" OFF)
303+
OPTION(WITH_ASAN_SCOPE "Enable -fsanitize-address-use-after-scope" OFF)
303304
IF(WITH_ASAN)
304305
MY_SANITIZER_CHECK("-fsanitize=address" WITH_ASAN_OK)
305306
IF(WITH_ASAN_OK)
306307
SET(HAVE_ASAN 1)
308+
# This works with clang, but not gcc it seems.
309+
MY_CHECK_CXX_COMPILER_FLAG(
310+
"-fsanitize=address -fsanitize-address-use-after-scope"
311+
HAVE_SANITIZE_SCOPE)
312+
IF(WITH_ASAN_SCOPE AND HAVE_SANITIZE_SCOPE)
313+
SET(CMAKE_C_FLAGS_DEBUG
314+
"${CMAKE_C_FLAGS_DEBUG} -fsanitize-address-use-after-scope")
315+
SET(CMAKE_C_FLAGS_RELWITHDEBINFO
316+
"${CMAKE_C_FLAGS_RELWITHDEBINFO} -fsanitize-address-use-after-scope")
317+
SET(CMAKE_CXX_FLAGS_DEBUG
318+
"${CMAKE_CXX_FLAGS_DEBUG} -fsanitize-address-use-after-scope")
319+
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO
320+
"${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -fsanitize-address-use-after-scope")
321+
ENDIF()
307322
ELSE()
308323
MESSAGE(FATAL_ERROR "Do not know how to enable address sanitizer")
309324
ENDIF()

0 commit comments

Comments
 (0)