Skip to content

Commit

Permalink
Suppress hash() clang integer sanitizer issues (doctest#667)
Browse files Browse the repository at this point in the history
* Add sanitizer CI

* Fix setup

* Separate sanatizers

* Add integer sanitizers

* Finalize sanitizer list

* Specify libc++

* Remove overly complicated sanitizers

* Readd removed CI

* Suppress hash() clang integer sanitizer issues

* Add changes to parts

* Add version limit

Co-authored-by: Stefan <29021710+Saalvage@users.noreply.github.com>
  • Loading branch information
2 people authored and onqtam committed Feb 27, 2023
1 parent 975be2a commit 4ba20f9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,30 @@ jobs:
- name: Build
run: cmake --build build

sanitizers:
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-22.04

strategy:
fail-fast: false
matrix:
sanitizers: ["address", "thread", "undefined", "integer", "implicit-conversion", "nullability", "safe-stack"]

steps:
- uses: actions/checkout@v2

- name: Install
run: sudo apt-get install -y ninja-build

- name: Generate
run: cmake -B build -S . -G Ninja -D CMAKE_CXX_COMPILER=clang++ -D CMAKE_EXPORT_COMPILE_COMMANDS=ON -D CMAKE_CXX_FLAGS="-fsanitize=${{ matrix.sanitizers }}"

- name: Build
run: cmake --build build

- name: Test
run: ctest --test-dir build --no-tests=error

ci:
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
runs-on: ${{ matrix.os }}
Expand Down
10 changes: 10 additions & 0 deletions doctest/doctest.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,14 @@ DOCTEST_MSVC_SUPPRESS_WARNING(4623) // default constructor was implicitly define
#endif // DOCTEST_MSVC
#endif // DOCTEST_CONSTEXPR

#ifndef DOCTEST_NO_SANITIZE_INTEGER
#if DOCTEST_CLANG >= DOCTEST_COMPILER(3, 7, 0)
#define DOCTEST_NO_SANITIZE_INTEGER __attribute__((no_sanitize("integer")))
#else
#define DOCTEST_NO_SANITIZE_INTEGER
#endif
#endif // DOCTEST_NO_SANITIZE_INTEGER

// =================================================================================================
// == FEATURE DETECTION END ========================================================================
// =================================================================================================
Expand Down Expand Up @@ -4118,11 +4126,13 @@ namespace {
return false;
}

DOCTEST_NO_SANITIZE_INTEGER
unsigned long long hash(unsigned long long a, unsigned long long b) {
return (a << 5) + b;
}

// C string hash function (djb2) - taken from http://www.cse.yorku.ca/~oz/hash.html
DOCTEST_NO_SANITIZE_INTEGER
unsigned long long hash(const char* str) {
unsigned long long hash = 5381;
char c;
Expand Down
2 changes: 2 additions & 0 deletions doctest/parts/doctest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1059,11 +1059,13 @@ namespace {
return false;
}

DOCTEST_NO_SANITIZE_INTEGER
unsigned long long hash(unsigned long long a, unsigned long long b) {
return (a << 5) + b;
}

// C string hash function (djb2) - taken from http://www.cse.yorku.ca/~oz/hash.html
DOCTEST_NO_SANITIZE_INTEGER
unsigned long long hash(const char* str) {
unsigned long long hash = 5381;
char c;
Expand Down
8 changes: 8 additions & 0 deletions doctest/parts/doctest_fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,14 @@ DOCTEST_MSVC_SUPPRESS_WARNING(4623) // default constructor was implicitly define
#endif // DOCTEST_MSVC
#endif // DOCTEST_CONSTEXPR

#ifndef DOCTEST_NO_SANITIZE_INTEGER
#if DOCTEST_CLANG >= DOCTEST_COMPILER(3, 7, 0)
#define DOCTEST_NO_SANITIZE_INTEGER __attribute__((no_sanitize("integer")))
#else
#define DOCTEST_NO_SANITIZE_INTEGER
#endif
#endif // DOCTEST_NO_SANITIZE_INTEGER

// =================================================================================================
// == FEATURE DETECTION END ========================================================================
// =================================================================================================
Expand Down

0 comments on commit 4ba20f9

Please sign in to comment.