[compiler-rt] [CompilerRT] Add numerical sanitizer (PR #94322)
Alexander Shaposhnikov via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 17 20:57:12 PDT 2024
================
@@ -0,0 +1,158 @@
+//===-- nsan_stats.cc -----------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is a part of NumericalStabilitySanitizer.
+//
+// NumericalStabilitySanitizer statistics.
+//===----------------------------------------------------------------------===//
+
+#include "nsan/nsan_stats.h"
+
+#include "sanitizer_common/sanitizer_common.h"
+#include "sanitizer_common/sanitizer_placement_new.h"
+#include "sanitizer_common/sanitizer_stackdepot.h"
+#include "sanitizer_common/sanitizer_stacktrace.h"
+#include "sanitizer_common/sanitizer_symbolizer.h"
+
+#include <assert.h>
+#include <stdio.h>
+
+namespace __nsan {
+
+using namespace __sanitizer;
+
+Stats::Stats() {
+ CheckAndWarnings.Initialize(0);
+ TrackedLoads.Initialize(0);
+}
+
+Stats::~Stats() { Printf("deleting nsan stats\n"); }
+
+static uptr key(CheckTypeT CheckType, u32 StackId) {
+ return static_cast<uptr>(CheckType) +
+ StackId * static_cast<uptr>(CheckTypeT::kMaxCheckType);
+}
+
+template <typename MapT, typename VectorT, typename Fn>
+void UpdateEntry(CheckTypeT CheckTy, uptr PC, uptr BP, MapT *Map,
+ VectorT *Vector, Mutex *Mutex, Fn F) {
+ BufferedStackTrace Stack;
+ Stack.Unwind(PC, BP, nullptr, false);
+ u32 StackId = StackDepotPut(Stack);
+ typename MapT::Handle Handle(Map, key(CheckTy, StackId));
+ Lock L(Mutex);
----------------
alexander-shaposhnikov wrote:
unlike DenseMap AddrHashMap uses MmapOrDie* for memory allocation and avoids any deps on libc.
https://github.com/llvm/llvm-project/pull/94322
More information about the llvm-commits
mailing list