Skip to content

Commit

Permalink
ORC-1841: [C++][CI] Add UBSAN to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
luffy-zh committed Jan 20, 2025
1 parent ab084b5 commit 7d22d33
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/ubsan_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

name: Undefined behavior sanitizer tests

on:
pull_request:
paths-ignore:
- 'site/**'
- 'conan/**'
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.event.number || github.sha }}
cancel-in-progress: true

jobs:
asan-test:
name: "ASAN with ${{ matrix.compiler }} on Ubuntu"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
compiler: [gcc, clang]
include:
- compiler: gcc
cc: gcc
cxx: g++
- compiler: clang
cc: clang
cxx: clang++
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure and Build with UBSAN
env:
CC: ${{ matrix.cc }}
CXX: ${{ matrix.cxx }}
run: |
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DENABLE_UBSAN=ON -DBUILD_JAVA=OFF
make
- name: Run Tests
working-directory: build
env:
UBSAN_OPTIONS: print_stacktrace=1
run: |
ctest --output-on-failure
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ option(ORC_ENABLE_CLANG_TOOLS
"Enable Clang tools"
ON)

option(ENABLE_UBSAN
"Enable Undefined Behavior Sanitizer"
OFF)

# Make sure that a build type is selected
if (NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, default to ReleaseWithDebugInfo")
Expand Down Expand Up @@ -171,6 +175,16 @@ if (ENABLE_ASAN)
endif()
endif()

# Configure Undefined Behavior Sanitizer if enabled
if (ENABLE_UBSAN)
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined -fno-sanitize=alignment,vptr,function -fno-sanitize-recover=all")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined -fno-sanitize=alignment,vptr,function -fno-sanitize-recover=all")
message(STATUS "Undefined Behavior Sanitizer enabled")
else()
message(WARNING "Undefined Behavior Sanitizer is only supported for GCC and Clang compilers")
endif()

enable_testing()

INCLUDE(GNUInstallDirs) # Put it before ThirdpartyToolchain to make CMAKE_INSTALL_LIBDIR available.
Expand Down

0 comments on commit 7d22d33

Please sign in to comment.