Skip to content

Commit

Permalink
Static analyzer and warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre-dejoue committed Aug 26, 2023
1 parent 5ba997e commit 9b619a0
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ jobs:
runs-on: ${{ matrix.os }}-latest

env:
CMAKE_CONFIG_PROJECT: -DPICROSS_BUILD_CLI=ON -DPICROSS_BUILD_TESTS=ON -DPICROSS_BUILD_EXAMPLES=ON
CMAKE_CONFIG_EXTRA: ${{ matrix.os == 'macos' && format('-DCMAKE_OSX_ARCHITECTURES={0}', matrix.arch) || '' }}

steps:
- uses: actions/checkout@v3

- name: Configure CMake
run: cmake -B ${{ github.workspace }}/build -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DPICROSS_BUILD_CLI=ON -DPICROSS_BUILD_TESTS=ON ${{ env.CMAKE_CONFIG_EXTRA }}
run: cmake -B ${{ github.workspace }}/build -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} ${{ env.CMAKE_CONFIG_PROJECT }} ${{ env.CMAKE_CONFIG_EXTRA }}

- name: Build
working-directory: ${{ github.workspace }}/build
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/packaging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
runs-on: ${{ matrix.os }}-latest

env:
CMAKE_CONFIG_PROJECT: -DPICROSS_BUILD_CLI=ON -DPICROSS_BUILD_APP=ON
CMAKE_CONFIG_EXTRA: ${{ matrix.os == 'macos' && format('-DCMAKE_OSX_ARCHITECTURES={0}', matrix.arch) || '' }}

steps:
Expand All @@ -33,7 +34,7 @@ jobs:
sudo apt-get install -y xorg-dev libgl1-mesa-dev
- name: Configure CMake
run: cmake -B ${{ github.workspace }}/build -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DPICROSS_BUILD_CLI=ON -DPICROSS_BUILD_APP=ON ${{ env.CMAKE_CONFIG_EXTRA }}
run: cmake -B ${{ github.workspace }}/build -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} ${{ env.CMAKE_CONFIG_PROJECT }} ${{ env.CMAKE_CONFIG_EXTRA }}

- name: Build
working-directory: ${{ github.workspace }}/build
Expand Down
8 changes: 6 additions & 2 deletions cmake/config/compiler_options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ function(
/permissive- # standards conformance mode for MSVC compiler.
)

set(MSVC_ANALYZER
$<$<CONFIG:DEBUG>:/analyze> # Visual Studio static analyzer
)

set(CLANG_WARNINGS
-Wall
-Wextra # reasonable and standard
Expand Down Expand Up @@ -61,13 +65,13 @@ function(

if(WARNINGS_AS_ERRORS)
message(TRACE "Warnings are treated as errors")
list(APPEND MSVC_WARNINGS /WX)
list(APPEND CLANG_WARNINGS -Werror)
list(APPEND GCC_WARNINGS -Werror)
list(APPEND MSVC_WARNINGS /WX)
endif()

if(MSVC)
set(_WARNINGS_CXX ${MSVC_WARNINGS})
set(_WARNINGS_CXX ${MSVC_WARNINGS} ${MSVC_ANALYZER})
elseif(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
set(_WARNINGS_CXX ${CLANG_WARNINGS})
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
Expand Down
3 changes: 1 addition & 2 deletions src/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

# Dependencies
include(argagg)

include(compiler_options)

set(CLI_SOURCES
Expand All @@ -23,7 +22,7 @@ target_link_libraries(picross_solver_cli
argagg-lib
)

set_target_warnings(picross_solver_cli OFF)
set_target_warnings(picross_solver_cli ON)

install(TARGETS picross_solver_cli)

Expand Down
12 changes: 12 additions & 0 deletions src/cli/src/argagg_wrap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#ifdef _MSC_VER
#pragma warning( push )
#pragma warning( disable : 28020 ) // Warning C28020: The expression 'expr' is not true at this call
#endif

#include <argagg/argagg.hpp>

#ifdef _MSC_VER
#pragma warning( pop )
#endif
2 changes: 1 addition & 1 deletion src/cli/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <utils/input_grid_utils.h>
#include <utils/picross_file_io.h>

#include <argagg/argagg.hpp>
#include "argagg_wrap.h"

#include <cassert>
#include <chrono>
Expand Down
2 changes: 1 addition & 1 deletion src/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ target_link_libraries(example_1
picross::picross
)

set_target_warnings(example_1 OFF)
set_target_warnings(example_1 ON)
27 changes: 18 additions & 9 deletions src/tests/picross/src/bench_line_alternatives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ TEST_CASE("Bench full reduction", "[line_alternatives]")
bool bench_run = false;
BENCHMARK("N_100_K_1") {
reduction = full_reduction(constraint, known_tiles);
return bench_run = true;
bench_run = true;
return reduction;
};
if (bench_run)
{
Expand All @@ -59,7 +60,8 @@ TEST_CASE("Bench full reduction", "[line_alternatives]")
bool bench_run = false;
BENCHMARK("N_100_K_2") {
reduction = full_reduction(constraint, known_tiles);
return bench_run = true;
bench_run = true;
return true;
};
if (bench_run)
{
Expand All @@ -77,7 +79,8 @@ TEST_CASE("Bench full reduction", "[line_alternatives]")
bool bench_run = false;
BENCHMARK("COL 17") {
reduction = full_reduction(constraint, known_tiles);
return bench_run = true;
bench_run = true;
return reduction;
};
if (bench_run)
{
Expand All @@ -95,7 +98,8 @@ TEST_CASE("Bench full reduction", "[line_alternatives]")
bool bench_run = false;
BENCHMARK("ROW 45") {
reduction = full_reduction(constraint, known_tiles);
return bench_run = true;
bench_run = true;
return reduction;
};
if (bench_run)
{
Expand All @@ -113,7 +117,8 @@ TEST_CASE("Bench full reduction", "[line_alternatives]")
bool bench_run = false;
BENCHMARK("ROW 46") {
reduction = full_reduction(constraint, known_tiles);
return bench_run = true;
bench_run = true;
return reduction;
};
if (bench_run)
{
Expand All @@ -131,7 +136,8 @@ TEST_CASE("Bench full reduction", "[line_alternatives]")
bool bench_run = false;
BENCHMARK("ROW 48") {
reduction = full_reduction(constraint, known_tiles);
return bench_run = true;
bench_run = true;
return reduction;
};
if (bench_run)
{
Expand Down Expand Up @@ -159,7 +165,8 @@ TEST_CASE("Bench linear vs full reduction", "[line_alternatives]")
std::string bench_name = "Threes " + std::to_string(nb_alt) + " linear";
BENCHMARK(std::move(bench_name)) {
reduction = linear_reduction(constraint, known_tiles);
return bench_run = true;
bench_run = true;
return reduction;
};
if (bench_run)
{
Expand All @@ -173,7 +180,8 @@ TEST_CASE("Bench linear vs full reduction", "[line_alternatives]")
std::string bench_name = "Threes " + std::to_string(nb_alt) + " full";
BENCHMARK(std::move(bench_name)) {
reduction = full_reduction(constraint, known_tiles);
return bench_run = true;
bench_run = true;
return reduction;
};
if (bench_run)
{
Expand All @@ -187,7 +195,8 @@ TEST_CASE("Bench linear vs full reduction", "[line_alternatives]")
std::string bench_name = "Threes " + std::to_string(nb_alt) + " full buf";
BENCHMARK(std::move(bench_name)) {
reduction = full_reduction(constraint, known_tiles, &buffers);
return bench_run = true;
bench_run = true;
return reduction;
};
if (bench_run)
{
Expand Down

0 comments on commit 9b619a0

Please sign in to comment.