Skip to content

Commit dd6838c

Browse files
committed
Fix GCC build (it errors with #if defined(__has_feature) && __has_feature(thread_sanitizer) since __has_feature is not recognized.)
1 parent c5e86dc commit dd6838c

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

benchmarks/BenchGuardedVectorExample.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
#include "../examples/GuardedVectorExample.h"
22

33
#include <nanobench.h>
4+
#include <chrono>
45

56
#include <vector>
67

8+
#if defined(__has_feature) // Clang
9+
# if __has_feature(thread_sanitizer)
10+
# define USING_THREAD_SANITIZER 1
11+
# endif
12+
#elif defined(__SANITIZE_THREAD__) // GCC
13+
# define USING_THREAD_SANITIZER 1
14+
#else
15+
# define USING_THREAD_SANITIZER 0
16+
#endif
717

818
using namespace std::chrono_literals;
919
const auto minEpoch = 100ms;
@@ -35,7 +45,7 @@ int BenchVector(ankerl::nanobench::Bench& bench, bool withNoReserve)
3545
}
3646
}
3747

38-
#if defined(__has_feature) && __has_feature(thread_sanitizer)
48+
#if !USING_THREAD_SANITIZER
3949
#ifndef NDEBUG // Only gives different perf in debug builds
4050
{
4151
ExampleGuardedVector<T> guardedvector;
@@ -73,7 +83,7 @@ int BenchVector(ankerl::nanobench::Bench& bench, bool withNoReserve)
7383
});
7484
}
7585
}
76-
#endif //defined(__has_feature) && __has_feature(thread_sanitizer)
86+
#endif //!USING_THREAD_SANITIZER
7787
if (withNoReserve)
7888
{
7989
{
@@ -94,7 +104,7 @@ int BenchVector(ankerl::nanobench::Bench& bench, bool withNoReserve)
94104
}
95105
}
96106

97-
#if defined(__has_feature) && __has_feature(thread_sanitizer)
107+
#if !USING_THREAD_SANITIZER
98108
{
99109
ExampleGuardedVector<T> guardedvector;
100110
for (size_t size : nbPushBacksPerIteration)
@@ -112,8 +122,8 @@ int BenchVector(ankerl::nanobench::Bench& bench, bool withNoReserve)
112122
});
113123
}
114124
}
125+
#endif //!USING_THREAD_SANITIZER
115126
}
116-
#endif //defined(__has_feature) && __has_feature(thread_sanitizer)
117127
return x;
118128
}
119129

src/BadAccessGuards.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@
1919
#endif
2020

2121
// Disable the guards when running ThreadSanitizer, we are racy by design!
22-
#if defined(__has_feature) && __has_feature(thread_sanitizer)
22+
#if defined(__has_feature) // Clang
23+
# if __has_feature(thread_sanitizer) // Can't be checked in same #if than defined or it will break old GCC versions
24+
# undef BAD_ACCESS_GUARDS_ENABLE
25+
# define BAD_ACCESS_GUARDS_ENABLE 0
26+
# endif
27+
#elif defined(__SANITIZE_THREAD__) // GCC
2328
# undef BAD_ACCESS_GUARDS_ENABLE
2429
# define BAD_ACCESS_GUARDS_ENABLE 0
2530
#endif

0 commit comments

Comments
 (0)