Skip to content

Commit c287bcd

Browse files
committed
Add support for GCC static analyzer and ASAN
Also enable the static analyzer in the linux build.
1 parent 12dbdf0 commit c287bcd

File tree

2 files changed

+68
-3
lines changed

2 files changed

+68
-3
lines changed

.github/workflows/ci.yml

+37-2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,24 @@ jobs:
1313
matrix:
1414
os: [ubuntu-latest, macos-latest, windows-latest]
1515
include:
16-
- os: ubuntu-latest
16+
# Use 24.04 explicitly to get newer GCC version
17+
- os: ubuntu-24.04
18+
compiler: gcc
19+
gcc: 14
20+
extra_c_flags: "-fdiagnostics-format=sarif-file"
1721
coverage: ON
22+
analysis: ON
23+
asan: ON
1824
- os: macos-latest
25+
extra_c_flags: ""
1926
coverage: OFF
27+
analysis: OFF
28+
asan: OFF
2029
- os: windows-latest
30+
extra_c_flags: ""
2131
coverage: OFF
32+
analysis: OFF
33+
asan: OFF
2234

2335
runs-on: ${{ matrix.os }}
2436

@@ -34,7 +46,15 @@ jobs:
3446
- name: Configure
3547
shell: bash
3648
working-directory: ${{ runner.workspace }}/build
37-
run: cmake --warn-uninitialized -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DQDLDL_UNITTESTS=ON -DCOVERAGE=${{ matrix.coverage }} $GITHUB_WORKSPACE
49+
run: |
50+
cmake -S $GITHUB_WORKSPACE -B ${{ runner.workspace }}/build \
51+
--warn-uninitialized \
52+
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
53+
-DQDLDL_UNITTESTS=ON \
54+
-DQDLDL_DEV_COVERAGE=${{ matrix.coverage }} \
55+
-DQDLDL_DEV_ANALYSIS=${{ matrix.analysis }} \
56+
-DQDLDL_DEV_ASAN=${{ matrix.asan }} \
57+
-DCMAKE_C_FLAGS=${{ matrix.extra_c_flags }}
3858
3959
- name: Build
4060
shell: bash
@@ -62,6 +82,21 @@ jobs:
6282
github-token: ${{ secrets.GITHUB_TOKEN }}
6383
path-to-lcov: '${{ runner.workspace }}/build/coverage.info'
6484

85+
- name: Merge diagnostics
86+
if: ${{ matrix.analysis == 'ON' }}
87+
uses: microsoft/[email protected]
88+
with:
89+
# Command to be sent to SARIF Multitool
90+
command: 'merge ${{ runner.workspace }}/build/*.sarif --recurse true file.sarif --output-directory=${{ runner.workspace }}/build/ --output-file=gcc.sarif'
91+
92+
- name: Upload diagnostics
93+
if: ${{ matrix.analysis == 'ON' }}
94+
uses: github/codeql-action/upload-sarif@v3
95+
with:
96+
# Path to SARIF file relative to the root of the repository
97+
sarif_file: ${{ runner.workspace }}/build/gcc.sarif
98+
category: gcc
99+
65100

66101
test_configs:
67102
strategy:

CMakeLists.txt

+31-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ set(QDLDL_VERSION "${QDLDL_VERSION_MAJOR}.${QDLDL_VERSION_MINOR}.${QDLDL_VERSION
1010
project(qdldl VERSION ${QDLDL_VERSION})
1111

1212
include( CMakeDependentOption )
13+
include( CheckCXXCompilerFlag )
1314

1415
option( QDLDL_BUILD_STATIC_LIB "Build the static library" ON )
1516
option( QDLDL_BUILD_SHARED_LIB "Build the shared library" ON )
@@ -24,6 +25,14 @@ cmake_dependent_option( QDLDL_UNITTESTS
2425
OFF # Default to off
2526
QDLDL_BUILD_STATIC_LIB OFF ) # Force off if the static library isn't built
2627

28+
# Dev options
29+
option( QDLDL_DEV_COVERAGE "Include coverage information in the library" OFF )
30+
option( QDLDL_DEV_ANALYSIS "Run the compiler static analysis checks" OFF )
31+
option( QDLDL_DEV_ASAN "Build with ASAN" OFF )
32+
33+
mark_as_advanced( OSQP_DEV_COVERAGE )
34+
mark_as_advanced( OSQP_DEV_ANALYSIS )
35+
2736
# Set the output folder where your program will be created
2837
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/out)
2938
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/out)
@@ -62,14 +71,35 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) # -fPIC
6271
# Add compiler options if we are not on windows
6372
if (NOT MSVC)
6473

65-
if (COVERAGE)
74+
if (QDLDL_DEV_COVERAGE)
6675
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")
6776

6877
if(FORTRAN)
6978
set(CMAKE_FORTRAN_FLAGS "${CMAKE_FORTRAN_FLAGS} --coverage")
7079
endif(FORTRAN)
7180
endif()
7281

82+
if (QDLDL_DEV_ANALYSIS)
83+
check_cxx_compiler_flag( "-fanalyzer" COMPILER_SUPPORTS_FANALYZER )
84+
85+
if( COMPILER_SUPPORTS_FANALYZER )
86+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fanalyzer")
87+
88+
message( STATUS "Enabling -fanalyzer static analysis" )
89+
endif()
90+
endif()
91+
92+
if(OSQP_ASAN)
93+
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -fsanitize=address -fno-optimize-sibling-calls -fsanitize-address-use-after-scope -fno-omit-frame-pointer" )
94+
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -D_GLIBCXX_SANITIZE_VECTOR -fsanitize=address -fno-optimize-sibling-calls -fsanitize-address-use-after-scope -fno-omit-frame-pointer" )
95+
96+
# ASAN shouldn't be used with these options (https://github.com/google/sanitizers/wiki/AddressSanitizer#faq)
97+
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-stack-protector -U_FORTIFY_SOURCE" )
98+
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-stack-protector -U_FORTIFY_SOURCE" )
99+
100+
message( STATUS "Enabling ASAN" )
101+
endif()
102+
73103
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
74104
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -g")
75105
endif (NOT MSVC)

0 commit comments

Comments
 (0)