diff --git a/Makefile b/Makefile index 996874703462d8e09d8feb6a24e4d57ac36499bf..0d383e95f088dc4d64d72e4e4461c504a4c4058e 100644 --- a/Makefile +++ b/Makefile @@ -83,6 +83,18 @@ lto: EMPER_B_LTO=true \ BUILDDIR="build-$@" +.PHONY: asan +asan: + rm -f build + $(MAKE) build \ + EMPER_LOG_LEVEL="Info" \ + EMPER_B_SANITIZE=address \ + BUILDDIR="build-$@" + +.PHONY: asan-test +asan-test: asan + meson test -C build-asan + .PHONY: fast-static-analysis fast-static-analysis: all check-format check-license doc diff --git a/emper/sleep_strategy/SemaphoreWorkerSleepStrategy.hpp b/emper/sleep_strategy/SemaphoreWorkerSleepStrategy.hpp index 9523826d0402065c4135120feb8bf90e8dc4c520..63e273c63180cd91eb6b93405c13686628506c74 100644 --- a/emper/sleep_strategy/SemaphoreWorkerSleepStrategy.hpp +++ b/emper/sleep_strategy/SemaphoreWorkerSleepStrategy.hpp @@ -175,7 +175,16 @@ class AbstractSemaphoreWorkerSleepStrategy AbstractSemaphoreWorkerSleepStrategy(Runtime& runtime, workerid_t workerCount) : workerCount(workerCount), stats(runtime) { if constexpr (useGenericNotifySpecificImpl) { - states = new (std::align_val_t(CACHE_LINE_SIZE)) std::atomic<SleeperState>[workerCount]; + // If ASAN is used, then it will rightfully complain about a + // mismatched aligned-new with and unaligned-delete + // below. However if we use the aligned-delete, then we get, at + // least on my machine, an "unused argumetn" error (see comment + // below). + states = new +#ifndef __SANITIZE_ADDRESS__ + (std::align_val_t(CACHE_LINE_SIZE)) +#endif + std::atomic<SleeperState>[workerCount]; } if constexpr (semNeedsInit) { @@ -183,7 +192,12 @@ class AbstractSemaphoreWorkerSleepStrategy } } - ~AbstractSemaphoreWorkerSleepStrategy() { delete[] states; } + ~AbstractSemaphoreWorkerSleepStrategy() { + // This should actually use an aligned delete, i.e., + // delete[](std::align_val_t(CACHE_LINE_SIZE), states); + // however, this throws "unused first argument" errors when compiling. + delete[] states; + } [[nodiscard]] inline auto getSleeping() const -> long { return wakeupSem.getValue(); }