Skip to content

Commit 4fefdef

Browse files
make sanitizer configurable
1 parent 5eca99c commit 4fefdef

File tree

5 files changed

+23
-13
lines changed

5 files changed

+23
-13
lines changed

.github/workflows/linux.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@
2626
fail-fast: false
2727
matrix:
2828
os: [ubuntu-24.04]
29-
compiler: [gcc-12, gcc-13, gcc-14, clang-16, clang-17, clang-18]
29+
compiler: [gcc-12, gcc-14, clang-16, clang-18]
3030
build_type: [Release, Debug]
3131
protoc: [find]
3232
include:
3333
- sanitize: OFF
3434
- build_type: Debug
35-
sanitize: ON
35+
sanitize: "address,undefined"
3636
- build_type: Coverage
3737
compiler: clang-18
3838
protoc: compile
@@ -76,7 +76,7 @@
7676
run: |
7777
cmake -GNinja -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
7878
-DHPP_PROTO_PROTOC=${{ matrix.protoc }} \
79-
-DHPP_PROTO_ENABLE_SANITIZER=${{ matrix.sanitize }} \
79+
-DHPP_PROTO_ENABLE_SANITIZERS=${{ matrix.sanitize }} \
8080
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
8181
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
8282

CMakeLists.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ option(HPP_PROTO_PROTOC_PLUGIN "Enable protoc plugin" ON)
1313
option(HPP_PROTO_TESTS "Enable HPP_PROTO tests" ${PROJECT_IS_TOP_LEVEL})
1414
option(HPP_PROTO_BENCHMARKS "Enable building benchmarks" OFF)
1515

16-
option(HPP_PROTO_ENABLE_SANITIZER "Enable address and undefined behavior sanitizer" OFF)
16+
option(HPP_PROTO_ENABLE_SANITIZERS "The sanitizer to enable" OFF)
1717
option(HPP_PROTO_BUILD_FUZZ "Build fuzz target" OFF)
1818
option(HPP_PROTO_TEST_USE_PROTOBUF "Use libprotobuf to generate data for tests" OFF)
1919

@@ -63,13 +63,13 @@ endif()
6363

6464
include(third-parties.cmake)
6565

66-
if(HPP_PROTO_ENABLE_SANITIZER)
66+
if(HPP_PROTO_ENABLE_SANITIZERS)
6767
if(MSVC)
6868
# add_compile_options("/fsanitize=address")
6969
# add_link_options("/fsanitize=address")
7070
else()
71-
add_compile_options("-fsanitize=address,undefined" "-fno-omit-frame-pointer")
72-
add_link_options("-fsanitize=address,undefined")
71+
add_compile_options("-fsanitize=${HPP_PROTO_ENABLE_SANITIZERS}" "-fno-omit-frame-pointer")
72+
add_link_options("-fsanitize=${HPP_PROTO_ENABLE_SANITIZERS}")
7373
endif()
7474
endif()
7575

CMakePresets.json

+12-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"cacheVariables": {
2828
"CMAKE_BUILD_TYPE": "Debug",
2929
"HPP_PROTO_PROTOC_PLUGIN": false,
30-
"HPP_PROTO_ENABLE_SANITIZER": true
30+
"HPP_PROTO_ENABLE_SANITIZERS": "address,undefined"
3131
}
3232
},
3333
{
@@ -38,10 +38,20 @@
3838
"binaryDir": "${sourceDir}/build/debug",
3939
"cacheVariables": {
4040
"CMAKE_BUILD_TYPE": "Debug",
41-
"HPP_PROTO_ENABLE_SANITIZER": true,
41+
"HPP_PROTO_ENABLE_SANITIZERS": "address,undefined",
4242
"HPP_PROTO_TEST_USE_PROTOBUF": true
4343
}
4444
},
45+
{
46+
"name": "dev-msan",
47+
"inherits": "default",
48+
"displayName": "Memory Sanitizer Mode",
49+
"binaryDir": "${sourceDir}/build/msan",
50+
"cacheVariables": {
51+
"CMAKE_BUILD_TYPE": "Debug",
52+
"HPP_PROTO_ENABLE_SANITIZERS": "memory"
53+
}
54+
},
4555
{
4656
"name": "release",
4757
"inherits": "default",

fuzz/CMakeLists.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
if(DEFINED ENV{LIB_FUZZING_ENGINE})
33
set(LIB_FUZZING_ENGINE $ENV{LIB_FUZZING_ENGINE})
44
else()
5-
set(FUZZ_COMPILE_FLAGS -fsanitize=fuzzer,address,undefined -fno-sanitize-recover=all)
6-
set(LIB_FUZZING_ENGINE -fsanitize=fuzzer,address,undefined)
5+
set(FUZZ_COMPILE_FLAGS "-fsanitize=fuzzer,${HPP_PROTO_ENABLE_SANITIZERS}" -fno-sanitize-recover=all)
6+
set(LIB_FUZZING_ENGINE "-fsanitize=fuzzer,${HPP_PROTO_ENABLE_SANITIZERS}")
77
endif()
88

99
function(add_fuzz_target target source)
@@ -14,7 +14,7 @@ function(add_fuzz_target target source)
1414

1515
if(DEFINED FUZZ_COMPILE_FLAGS)
1616
add_executable(${target}_debug_case ${source} fuzz_case_main.cpp)
17-
target_compile_options(${target}_debug_case PRIVATE -fsanitize=address,undefined)
17+
target_compile_options(${target}_debug_case PRIVATE -fsanitize=${HPP_PROTO_ENABLE_SANITIZERS})
1818
target_link_libraries(${target}_debug_case PRIVATE hpp_proto::libhpp_proto unittest_proto_lib)
1919
endif()
2020
endfunction()

tutorial/grpc/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
find_package(gRPC CONFIG 1.51)
22

3-
if(gRPC_FOUND AND NOT HPP_PROTO_ENABLE_SANITIZER)
3+
if(gRPC_FOUND AND NOT HPP_PROTO_ENABLE_SANITIZERS)
44
## when sanitizer is enable, we can't use gRPC unless the gRPC library is built with sanitizer.
55
add_library(helloworld INTERFACE)
66

0 commit comments

Comments
 (0)