Skip to content

Commit 72dc7bf

Browse files
committed
cmake : add sanitizer flags for llama.cpp
ggml-ci
1 parent 3edfa7d commit 72dc7bf

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

common/CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@ find_package(Threads REQUIRED)
44

55
llama_add_compile_flags()
66

7+
if (NOT MSVC)
8+
if (LLAMA_SANITIZE_THREAD)
9+
add_compile_options(-fsanitize=thread)
10+
link_libraries (-fsanitize=thread)
11+
endif()
12+
13+
if (LLAMA_SANITIZE_ADDRESS)
14+
add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
15+
link_libraries (-fsanitize=address)
16+
endif()
17+
18+
if (LLAMA_SANITIZE_UNDEFINED)
19+
add_compile_options(-fsanitize=undefined)
20+
link_libraries (-fsanitize=undefined)
21+
endif()
22+
endif()
23+
724
# Build info header
825
#
926

examples/CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,23 @@ find_package(Threads REQUIRED)
1010

1111
llama_add_compile_flags()
1212

13+
if (NOT MSVC)
14+
if (LLAMA_SANITIZE_THREAD)
15+
add_compile_options(-fsanitize=thread)
16+
link_libraries (-fsanitize=thread)
17+
endif()
18+
19+
if (LLAMA_SANITIZE_ADDRESS)
20+
add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
21+
link_libraries (-fsanitize=address)
22+
endif()
23+
24+
if (LLAMA_SANITIZE_UNDEFINED)
25+
add_compile_options(-fsanitize=undefined)
26+
link_libraries (-fsanitize=undefined)
27+
endif()
28+
endif()
29+
1330
# examples
1431

1532
include_directories(${CMAKE_CURRENT_SOURCE_DIR})

src/CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
llama_add_compile_flags()
22

3+
if (NOT MSVC)
4+
if (LLAMA_SANITIZE_THREAD)
5+
add_compile_options(-fsanitize=thread)
6+
link_libraries (-fsanitize=thread)
7+
endif()
8+
9+
if (LLAMA_SANITIZE_ADDRESS)
10+
add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
11+
link_libraries (-fsanitize=address)
12+
endif()
13+
14+
if (LLAMA_SANITIZE_UNDEFINED)
15+
add_compile_options(-fsanitize=undefined)
16+
link_libraries (-fsanitize=undefined)
17+
endif()
18+
endif()
19+
320
#
421
# libraries
522
#

tests/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
llama_add_compile_flags()
2+
3+
if (NOT MSVC)
4+
if (LLAMA_SANITIZE_THREAD)
5+
add_compile_options(-fsanitize=thread)
6+
link_libraries (-fsanitize=thread)
7+
endif()
8+
9+
if (LLAMA_SANITIZE_ADDRESS)
10+
add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
11+
link_libraries (-fsanitize=address)
12+
endif()
13+
14+
if (LLAMA_SANITIZE_UNDEFINED)
15+
add_compile_options(-fsanitize=undefined)
16+
link_libraries (-fsanitize=undefined)
17+
endif()
18+
endif()
19+
120
function(llama_test target)
221
include(CMakeParseArguments)
322
set(options)

0 commit comments

Comments
 (0)