Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: add sanitizers #3625

Merged
merged 3 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nit, maybe also rename the top-level test to include this name. Then the label immediately shows in the action panel.

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 @@ -174,6 +174,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