Skip to content

Commit

Permalink
CI: add sanitizers (p4lang#3625)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbolvansky authored Nov 2, 2022
1 parent 95aa178 commit 7867db4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ concurrency:

jobs:
# Build with gcc and test p4c on Ubuntu 20.04.
build-linux:
build-linux-sanitizers:
strategy:
fail-fast: false
matrix:
Expand All @@ -32,9 +32,9 @@ jobs:
key: test-${{ matrix.unified }}-${{ runner.os }}-gcc
max-size: 1000M

- name: Build (Ubuntu Linux, GCC)
- name: Build (Ubuntu Linux, GCC, Sanitizers)
run: |
docker build -t p4c --build-arg IMAGE_TYPE=test --build-arg ENABLE_UNIFIED_COMPILATION=${{ matrix.unified }} .
docker build -t p4c --build-arg IMAGE_TYPE=test --build-arg ENABLE_UNIFIED_COMPILATION=${{ matrix.unified }} --build-arg ENABLE_SANITIZERS=ON .
./tools/export_ccache.sh
# run with sudo (...) --privileged
Expand Down
12 changes: 10 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ OPTION (ENABLE_GC "Use libgc" ON)
OPTION (ENABLE_MULTITHREAD "Use multithreading" OFF)
OPTION (ENABLE_LTO "Enable Link Time Optimization (LTO)" OFF)
OPTION (ENABLE_WERROR "Treat warnings as errors" OFF)
OPTION (ENABLE_SANITIZERS "Enable sanitizers" OFF)
OPTION (BUILD_STATIC_RELEASE "Build a statically linked release binary" OFF)

set (P4C_DRIVER_NAME "p4c" CACHE STRING "Customize the name of the driver script")
Expand Down Expand Up @@ -213,11 +214,18 @@ add_cxx_compiler_option ("-Wextra")
add_cxx_compiler_option ("-Wno-overloaded-virtual")
add_cxx_compiler_option ("-Wno-deprecated")
add_cxx_compiler_option ("-Wno-deprecated-declarations")
# Enable/disable runtime exceptions on nullpointer dereferencing
# add_cxx_compiler_option ("-fsanitize=null")

if (ENABLE_SANITIZERS)
add_cxx_compiler_option ("-fsanitize=undefined,address")
endif ()

if (ENABLE_WERROR)
add_cxx_compiler_option ("-Werror")
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# GCC's -Waybe-uninitialized warnings are quite noisy and unlikely to catch
# real issues - do not treat them as build errors.
add_cxx_compiler_option ("-Wno-error=maybe-uninitialized")
endif ()
endif ()

# If we're on GCC or Clang, use the prefer LLD or Gold linker if available.
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ ARG ENABLE_TEST_TOOLS=OFF
ARG ENABLE_WERROR=ON
# Compile with Clang compiler
ARG COMPILE_WITH_CLANG=OFF
# Compile with sanitizers (UBSan, ASan)
ARG ENABLE_SANITIZERS=OFF

# Delegate the build to tools/ci-build.
COPY . /p4c/
Expand Down
2 changes: 2 additions & 0 deletions tools/ci-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ CMAKE_FLAGS+="-DENABLE_TEST_TOOLS=${ENABLE_TEST_TOOLS} "
CMAKE_FLAGS+="-DCMAKE_BUILD_TYPE=RELEASE "
# Treat warnings as errors.
CMAKE_FLAGS+="-DENABLE_WERROR=${ENABLE_WERROR} "
# Enable sanitizers.
CMAKE_FLAGS+="-DENABLE_SANITIZERS=${ENABLE_SANITIZERS} "
build ${CMAKE_FLAGS}

make install
Expand Down

0 comments on commit 7867db4

Please sign in to comment.