Skip to content

Commit

Permalink
feat: Create a basic rocbuild_enable_asan()
Browse files Browse the repository at this point in the history
  • Loading branch information
zchrissirhcz committed Dec 11, 2024
1 parent 8e2cc80 commit a1bd168
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
10 changes: 10 additions & 0 deletions rocbuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,16 @@ function(rocbuild_print_args)
endfunction()


function(rocbuild_enable_asan TARGET)
if(MSVC)
target_compile_options(${TARGET} PUBLIC /fsanitize=address)
else()
target_compile_options(${TARGET} PUBLIC -fsanitize=address -fno-omit-frame-pointer -g)
target_link_options(${TARGET} PUBLIC -fsanitize=address)
endif()
endfunction()


rocbuild_print_args()
rocbuild_set_artifacts_path()
rocbuild_enable_ninja_colorful_output()
8 changes: 8 additions & 0 deletions tests/asan/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.10)
project(asan)

include(../../rocbuild.cmake)

add_executable(test basic-global-overflow.cpp)

rocbuild_enable_asan(test)
7 changes: 7 additions & 0 deletions tests/asan/basic-global-overflow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <stdio.h>
int x[100];
int main() {
printf("Hello!\n");
x[100] = 5; // Boom!
return 0;
}

0 comments on commit a1bd168

Please sign in to comment.