[compiler-rt] [rtsan] Add exit statistics (PR #109885)

Chris Apple via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 25 06:01:10 PDT 2024


================
@@ -0,0 +1,35 @@
+//===--- rtsan_stats.cpp - Realtime Sanitizer -------------------*- C++ -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+//
+// Part of the RealtimeSanitizer runtime library
+//
+//===----------------------------------------------------------------------===//
+
+#include "rtsan/rtsan_stats.h"
+
+#include "sanitizer_common/sanitizer_atomic.h"
+#include "sanitizer_common/sanitizer_common.h"
+
+using namespace __sanitizer;
+using namespace __rtsan;
+
+static atomic_uint32_t rtsan_total_error_count{0};
+
+void __rtsan::IncrementTotalErrorCount() {
----------------
cjappl wrote:

This was advice we were given on one of our first PRs, which seems to originate from the LLVM Coding Standard: https://llvm.org/docs/CodingStandards.html#use-namespace-qualifiers-to-implement-previously-declared-functions

> Doing this helps to avoid bugs where the definition does not match the declaration from the header. For example, the following C++ code defines a new overload of llvm::foo instead of providing a definition for the existing function declared in the header:

```
// Foo.cpp
#include "Foo.h"
namespace llvm {
int foo(char *s) { // Mismatch between "const char *" and "char *"
}
} // namespace llvm
```

> This error will not be caught until the build is nearly complete, when the linker fails to find a definition for any uses of the original function. If the function were instead defined with a namespace qualifier, the error would have been caught immediately when the definition was compiled.

https://github.com/llvm/llvm-project/pull/109885


More information about the llvm-commits mailing list