From d9888fcefc216b16404a39ac7b82a8fd8d5f343f Mon Sep 17 00:00:00 2001 From: Martin Nowack Date: Thu, 19 Dec 2019 15:23:37 +0000 Subject: Remove statistics limit from istats. Statistics encoded in `run.istats` were limited to a maximum number of 13 due to encoding in a `uint64_t` variable. This approach has multiple limitations: - a maximum number of 13 statistics were allowed - a subtle bug can be triggered if many more statistics are added - independent of the selected statistics for `run.istats` Depending on the linking order, statistics will get a different ID. Previously, the ID was used to shift a `1` to its position marking the statistic as being used. This will lead to undefined behaviour if more than 63 statistics are used. Using an llvm::SmallBitVector instead fixes both problems. --- lib/Core/StatsTracker.cpp | 52 +++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/lib/Core/StatsTracker.cpp b/lib/Core/StatsTracker.cpp index d445eb2a..76ed9e08 100644 --- a/lib/Core/StatsTracker.cpp +++ b/lib/Core/StatsTracker.cpp @@ -26,19 +26,20 @@ #include "MemoryManager.h" #include "UserSearcher.h" +#include "llvm/ADT/SmallBitVector.h" #include "llvm/IR/BasicBlock.h" -#include "llvm/IR/CallSite.h" #include "llvm/IR/CFG.h" +#include "llvm/IR/CallSite.h" #include "llvm/IR/Function.h" +#include "llvm/IR/InlineAsm.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/IntrinsicInst.h" -#include "llvm/IR/InlineAsm.h" #include "llvm/IR/Module.h" #include "llvm/IR/Type.h" #include "llvm/Support/CommandLine.h" -#include "llvm/Support/Process.h" -#include "llvm/Support/Path.h" #include "llvm/Support/FileSystem.h" +#include "llvm/Support/Path.h" +#include "llvm/Support/Process.h" #include #include @@ -579,7 +580,6 @@ void StatsTracker::updateStateStatistics(uint64_t addend) { void StatsTracker::writeIStats() { const auto m = executor.kmodule->module.get(); - uint64_t istatsMask = 0; llvm::raw_fd_ostream &of = *istatsFile; // We assume that we didn't move the file pointer @@ -595,26 +595,26 @@ void StatsTracker::writeIStats() { StatisticManager &sm = *theStatisticManager; unsigned nStats = sm.getNumStatistics(); - - // Max is 13, sadly - istatsMask |= 1<