[Lldb-commits] [clang] [compiler-rt] [libcxx] [lldb] [llvm] Rename Sanitizer Coverage => Coverage Sanitizer (PR #106505)
via lldb-commits
lldb-commits at lists.llvm.org
Thu Aug 29 00:55:58 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff ec9f36a624fa9f8fea6e40384ce513b6da8c08e4 adb4a0eb00972811343ff05eac6977512f01970a --extensions c,h,inc,cpp -- clang/include/clang/Basic/CodeGenOptions.h clang/lib/CodeGen/BackendUtil.cpp clang/lib/Driver/SanitizerArgs.cpp clang/test/CodeGen/sancov-new-pm.c clang/test/Driver/sancov.c compiler-rt/include/sanitizer/common_interface_defs.h compiler-rt/include/sanitizer/coverage_interface.h compiler-rt/lib/fuzzer/dataflow/DataFlow.cpp compiler-rt/lib/sanitizer_common/sancov_flags.cpp compiler-rt/lib/sanitizer_common/sancov_flags.h compiler-rt/lib/sanitizer_common/sancov_flags.inc compiler-rt/test/asan/TestCases/Darwin/interface_symbols_darwin.cpp compiler-rt/test/asan/TestCases/Linux/interface_symbols_linux.cpp compiler-rt/test/asan/TestCases/Posix/coverage-reset.cpp compiler-rt/test/asan/TestCases/coverage-and-lsan.cpp llvm/include/llvm/Transforms/Instrumentation.h llvm/lib/Passes/PassBuilder.cpp llvm/tools/sancov/sancov.cpp compiler-rt/lib/sanitizer_common/coverage_sanitizer_fuchsia.cpp compiler-rt/lib/sanitizer_common/coverage_sanitizer_interface.inc compiler-rt/lib/sanitizer_common/coverage_sanitizer_libcdep_new.cpp compiler-rt/lib/sanitizer_common/coverage_sanitizer_win_dll_thunk.cpp compiler-rt/lib/sanitizer_common/coverage_sanitizer_win_dynamic_runtime_thunk.cpp compiler-rt/lib/sanitizer_common/coverage_sanitizer_win_sections.cpp compiler-rt/lib/sanitizer_common/coverage_sanitizer_win_weak_interception.cpp compiler-rt/test/sanitizer_common/TestCases/coverage_sanitizer_allowlist_ignorelist.cpp compiler-rt/test/sanitizer_common/TestCases/coverage_sanitizer_control_flow.cpp compiler-rt/test/sanitizer_common/TestCases/coverage_sanitizer_inline8bit_counter.cpp compiler-rt/test/sanitizer_common/TestCases/coverage_sanitizer_inline8bit_counter_default_impl.cpp compiler-rt/test/sanitizer_common/TestCases/coverage_sanitizer_inline_bool_flag.cpp compiler-rt/test/sanitizer_common/TestCases/coverage_sanitizer_no_prune.cpp compiler-rt/test/sanitizer_common/TestCases/coverage_sanitizer_stack_depth.cpp compiler-rt/test/sanitizer_common/TestCases/coverage_sanitizer_symbolize.cpp compiler-rt/test/sanitizer_common/TestCases/coverage_sanitizer_trace_loads_stores.cpp compiler-rt/test/sanitizer_common/TestCases/coverage_sanitizer_trace_pc_guard-dso.cpp compiler-rt/test/sanitizer_common/TestCases/coverage_sanitizer_trace_pc_guard-init.cpp compiler-rt/test/sanitizer_common/TestCases/coverage_sanitizer_trace_pc_guard.cpp llvm/include/llvm/Transforms/Instrumentation/CoverageSanitizer.h llvm/lib/Transforms/Instrumentation/CoverageSanitizer.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 3301a0f9b5..382cee4527 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -68,6 +68,7 @@
#include "llvm/Transforms/Instrumentation/AddressSanitizer.h"
#include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"
#include "llvm/Transforms/Instrumentation/BoundsChecking.h"
+#include "llvm/Transforms/Instrumentation/CoverageSanitizer.h"
#include "llvm/Transforms/Instrumentation/DataFlowSanitizer.h"
#include "llvm/Transforms/Instrumentation/GCOVProfiler.h"
#include "llvm/Transforms/Instrumentation/HWAddressSanitizer.h"
@@ -80,7 +81,6 @@
#include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
#include "llvm/Transforms/Instrumentation/RealtimeSanitizer.h"
#include "llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h"
-#include "llvm/Transforms/Instrumentation/CoverageSanitizer.h"
#include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
#include "llvm/Transforms/ObjCARC.h"
#include "llvm/Transforms/Scalar/EarlyCSE.h"
diff --git a/compiler-rt/lib/sanitizer_common/coverage_sanitizer_fuchsia.cpp b/compiler-rt/lib/sanitizer_common/coverage_sanitizer_fuchsia.cpp
index 9343079f78..026b669a1c 100644
--- a/compiler-rt/lib/sanitizer_common/coverage_sanitizer_fuchsia.cpp
+++ b/compiler-rt/lib/sanitizer_common/coverage_sanitizer_fuchsia.cpp
@@ -27,14 +27,14 @@
#include "sanitizer_platform.h"
#if SANITIZER_FUCHSIA
-#include <zircon/process.h>
-#include <zircon/sanitizer.h>
-#include <zircon/syscalls.h>
-
-#include "sanitizer_atomic.h"
-#include "sanitizer_common.h"
-#include "sanitizer_interface_internal.h"
-#include "sanitizer_internal_defs.h"
+# include <zircon/process.h>
+# include <zircon/sanitizer.h>
+# include <zircon/syscalls.h>
+
+# include "sanitizer_atomic.h"
+# include "sanitizer_common.h"
+# include "sanitizer_interface_internal.h"
+# include "sanitizer_internal_defs.h"
# include "sanitizer_symbolizer_markup_constants.h"
using namespace __sanitizer;
diff --git a/compiler-rt/lib/sanitizer_common/coverage_sanitizer_libcdep_new.cpp b/compiler-rt/lib/sanitizer_common/coverage_sanitizer_libcdep_new.cpp
index ab4d080538..95e0d0c48e 100644
--- a/compiler-rt/lib/sanitizer_common/coverage_sanitizer_libcdep_new.cpp
+++ b/compiler-rt/lib/sanitizer_common/coverage_sanitizer_libcdep_new.cpp
@@ -57,7 +57,8 @@ static void WriteModuleCoverage(char* file_path, const char* module_name,
}
static void SanitizerDumpCoverage(const uptr* unsorted_pcs, uptr len) {
- if (!len) return;
+ if (!len)
+ return;
char* file_path = static_cast<char*>(InternalAlloc(kMaxPathLength));
char* module_name = static_cast<char*>(InternalAlloc(kMaxPathLength));
@@ -72,7 +73,8 @@ static void SanitizerDumpCoverage(const uptr* unsorted_pcs, uptr len) {
for (uptr i = 0; i < len; ++i) {
const uptr pc = pcs[i];
- if (!pc) continue;
+ if (!pc)
+ continue;
if (!GetModuleAndOffsetForPc(pc, nullptr, 0, &pcs[i])) {
Printf("ERROR: unknown pc %p (may happen if dlclose is used)\n",
@@ -118,7 +120,8 @@ class TracePcGuardController {
}
void InitTracePcGuard(u32* start, u32* end) {
- if (!initialized) Initialize();
+ if (!initialized)
+ Initialize();
CHECK(!*start);
CHECK_NE(start, end);
@@ -129,7 +132,8 @@ class TracePcGuardController {
void TracePcGuard(u32* guard, uptr pc) {
u32 idx = *guard;
- if (!idx) return;
+ if (!idx)
+ return;
// we start indices from 1.
atomic_uintptr_t* pc_ptr =
reinterpret_cast<atomic_uintptr_t*>(&pc_vector[idx - 1]);
@@ -142,7 +146,8 @@ class TracePcGuardController {
}
void Dump() {
- if (!initialized || !common_flags()->coverage) return;
+ if (!initialized || !common_flags()->coverage)
+ return;
__sanitizer_dump_coverage(pc_vector.data(), pc_vector.size());
}
@@ -206,7 +211,7 @@ static void CovPcsInit(const uptr* beg, const uptr* end) {
} // namespace __sancov
namespace __sanitizer {
-void InitializeCoverage(bool enabled, const char *dir) {
+void InitializeCoverage(bool enabled, const char* dir) {
static bool coverage_enabled = false;
if (coverage_enabled)
return; // May happen if two sanitizer enable coverage in the same process.
@@ -214,7 +219,7 @@ void InitializeCoverage(bool enabled, const char *dir) {
Atexit(__sanitizer_cov_dump);
AddDieCallback(__sanitizer_cov_dump);
}
-} // namespace __sanitizer
+} // namespace __sanitizer
extern "C" {
SANITIZER_INTERFACE_ATTRIBUTE void __sanitizer_dump_coverage(const uptr* pcs,
@@ -223,14 +228,16 @@ SANITIZER_INTERFACE_ATTRIBUTE void __sanitizer_dump_coverage(const uptr* pcs,
}
SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_cov_trace_pc_guard, u32* guard) {
- if (!*guard) return;
+ if (!*guard)
+ return;
__sancov::pc_guard_controller.TracePcGuard(
guard, StackTrace::GetPreviousInstructionPc(GET_CALLER_PC()));
}
SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_cov_trace_pc_guard_init,
u32* start, u32* end) {
- if (start == end || *start) return;
+ if (start == end || *start)
+ return;
__sancov::pc_guard_controller.InitTracePcGuard(start, end);
}
@@ -260,16 +267,16 @@ SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_cov_trace_div4, void) {}
SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_cov_trace_div8, void) {}
SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_cov_trace_gep, void) {}
SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_cov_trace_pc_indir, void) {}
-SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_cov_load1, void){}
-SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_cov_load2, void){}
-SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_cov_load4, void){}
-SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_cov_load8, void){}
-SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_cov_load16, void){}
-SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_cov_store1, void){}
-SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_cov_store2, void){}
-SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_cov_store4, void){}
-SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_cov_store8, void){}
-SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_cov_store16, void){}
+SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_cov_load1, void) {}
+SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_cov_load2, void) {}
+SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_cov_load4, void) {}
+SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_cov_load8, void) {}
+SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_cov_load16, void) {}
+SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_cov_store1, void) {}
+SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_cov_store2, void) {}
+SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_cov_store4, void) {}
+SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_cov_store8, void) {}
+SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_cov_store16, void) {}
SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_cov_8bit_counters_init,
char* start, char* end) {
__sancov::SingletonCounterCoverage::Cov8bitCountersInit(start, end);
@@ -288,9 +295,9 @@ SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_cov_pcs_init, const uptr* beg,
// FIXME: Figure out how this should work on Windows, exported thread_local
// symbols are not supported:
// "data with thread storage duration may not have dll interface"
-#if !SANITIZER_APPLE && !SANITIZER_WINDOWS
-SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
-thread_local uptr __sancov_lowest_stack;
-#endif
+# if !SANITIZER_APPLE && !SANITIZER_WINDOWS
+SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE thread_local uptr
+ __sancov_lowest_stack;
+# endif
#endif // !SANITIZER_FUCHSIA
diff --git a/compiler-rt/lib/sanitizer_common/coverage_sanitizer_win_dll_thunk.cpp b/compiler-rt/lib/sanitizer_common/coverage_sanitizer_win_dll_thunk.cpp
index 7eb503da37..cd95191ec3 100644
--- a/compiler-rt/lib/sanitizer_common/coverage_sanitizer_win_dll_thunk.cpp
+++ b/compiler-rt/lib/sanitizer_common/coverage_sanitizer_win_dll_thunk.cpp
@@ -12,9 +12,9 @@
// See https://github.com/google/sanitizers/issues/209 for the details.
//===----------------------------------------------------------------------===//
#ifdef SANITIZER_DLL_THUNK
-#include "sanitizer_win_dll_thunk.h"
+# include "sanitizer_win_dll_thunk.h"
// Coverage Sanitizer interface functions.
-#define INTERFACE_FUNCTION(Name) INTERCEPT_SANITIZER_FUNCTION(Name)
-#define INTERFACE_WEAK_FUNCTION(Name) INTERCEPT_SANITIZER_WEAK_FUNCTION(Name)
-#include "coverage_sanitizer_interface.inc"
-#endif // SANITIZER_DLL_THUNK
+# define INTERFACE_FUNCTION(Name) INTERCEPT_SANITIZER_FUNCTION(Name)
+# define INTERFACE_WEAK_FUNCTION(Name) INTERCEPT_SANITIZER_WEAK_FUNCTION(Name)
+# include "coverage_sanitizer_interface.inc"
+#endif // SANITIZER_DLL_THUNK
diff --git a/compiler-rt/lib/sanitizer_common/coverage_sanitizer_win_dynamic_runtime_thunk.cpp b/compiler-rt/lib/sanitizer_common/coverage_sanitizer_win_dynamic_runtime_thunk.cpp
index e7b024c7c4..b8786a7cc4 100644
--- a/compiler-rt/lib/sanitizer_common/coverage_sanitizer_win_dynamic_runtime_thunk.cpp
+++ b/compiler-rt/lib/sanitizer_common/coverage_sanitizer_win_dynamic_runtime_thunk.cpp
@@ -11,16 +11,16 @@
//
//===----------------------------------------------------------------------===//
#ifdef SANITIZER_DYNAMIC_RUNTIME_THUNK
-#define SANITIZER_IMPORT_INTERFACE 1
-#include "sanitizer_win_defs.h"
+# define SANITIZER_IMPORT_INTERFACE 1
+# include "sanitizer_win_defs.h"
// Define weak alias for all weak functions imported from coverage sanitizer.
-#define INTERFACE_FUNCTION(Name)
-#define INTERFACE_WEAK_FUNCTION(Name) WIN_WEAK_IMPORT_DEF(Name)
-#include "coverage_sanitizer_interface.inc"
-#endif // SANITIZER_DYNAMIC_RUNTIME_THUNK
+# define INTERFACE_FUNCTION(Name)
+# define INTERFACE_WEAK_FUNCTION(Name) WIN_WEAK_IMPORT_DEF(Name)
+# include "coverage_sanitizer_interface.inc"
+#endif // SANITIZER_DYNAMIC_RUNTIME_THUNK
namespace __sanitizer {
// Add one, otherwise unused, external symbol to this object file so that the
// Visual C++ linker includes it and reads the .drective section.
void ForceWholeArchiveIncludeForSanCov() {}
-}
+} // namespace __sanitizer
diff --git a/compiler-rt/lib/sanitizer_common/coverage_sanitizer_win_sections.cpp b/compiler-rt/lib/sanitizer_common/coverage_sanitizer_win_sections.cpp
index 5c4280341a..5c7871a1ff 100644
--- a/compiler-rt/lib/sanitizer_common/coverage_sanitizer_win_sections.cpp
+++ b/compiler-rt/lib/sanitizer_common/coverage_sanitizer_win_sections.cpp
@@ -25,13 +25,13 @@
#include "sanitizer_platform.h"
#if SANITIZER_WINDOWS
-#include <stdint.h>
+# include <stdint.h>
extern "C" {
// Use uint64_t so the linker won't need to add any padding if it tries to word
// align the start of the 8-bit counters array. The array will always start 8
// bytes after __start_sancov_cntrs.
-#pragma section(".SCOV$CA", read, write)
+# pragma section(".SCOV$CA", read, write)
__declspec(allocate(".SCOV$CA")) uint64_t __start___sancov_cntrs = 0;
// Even though we said not to align __stop__sancov_cntrs (using the "align"
@@ -41,27 +41,27 @@ __declspec(allocate(".SCOV$CA")) uint64_t __start___sancov_cntrs = 0;
// padding would be added to align .SCOVP$Z, However, if .SCOV$CZ section is 1
// byte, the linker won't try to align it on an 8-byte boundary, so use a
// uint8_t for __stop_sancov_cntrs.
-#pragma section(".SCOV$CZ", read, write)
-__declspec(allocate(".SCOV$CZ")) __declspec(align(1)) uint8_t
- __stop___sancov_cntrs = 0;
+# pragma section(".SCOV$CZ", read, write)
+__declspec(allocate(".SCOV$CZ"))
+__declspec(align(1)) uint8_t __stop___sancov_cntrs = 0;
-#pragma section(".SCOV$GA", read, write)
+# pragma section(".SCOV$GA", read, write)
__declspec(allocate(".SCOV$GA")) uint64_t __start___sancov_guards = 0;
-#pragma section(".SCOV$GZ", read, write)
-__declspec(allocate(".SCOV$GZ")) __declspec(align(1)) uint8_t
- __stop___sancov_guards = 0;
+# pragma section(".SCOV$GZ", read, write)
+__declspec(allocate(".SCOV$GZ"))
+__declspec(align(1)) uint8_t __stop___sancov_guards = 0;
// The guard array and counter array should both be merged into the .data
// section to reduce the number of PE sections. However, because PCTable is
// constant it should be merged with the .rdata section.
-#pragma comment(linker, "/MERGE:.SCOV=.data")
+# pragma comment(linker, "/MERGE:.SCOV=.data")
-#pragma section(".SCOVP$A", read)
+# pragma section(".SCOVP$A", read)
__declspec(allocate(".SCOVP$A")) uint64_t __start___sancov_pcs = 0;
-#pragma section(".SCOVP$Z", read)
-__declspec(allocate(".SCOVP$Z")) __declspec(align(1)) uint8_t
- __stop___sancov_pcs = 0;
+# pragma section(".SCOVP$Z", read)
+__declspec(allocate(".SCOVP$Z"))
+__declspec(align(1)) uint8_t __stop___sancov_pcs = 0;
-#pragma comment(linker, "/MERGE:.SCOVP=.rdata")
+# pragma comment(linker, "/MERGE:.SCOVP=.rdata")
}
#endif // SANITIZER_WINDOWS
diff --git a/compiler-rt/lib/sanitizer_common/coverage_sanitizer_win_weak_interception.cpp b/compiler-rt/lib/sanitizer_common/coverage_sanitizer_win_weak_interception.cpp
index c30a310e91..bad60b074f 100644
--- a/compiler-rt/lib/sanitizer_common/coverage_sanitizer_win_weak_interception.cpp
+++ b/compiler-rt/lib/sanitizer_common/coverage_sanitizer_win_weak_interception.cpp
@@ -11,13 +11,13 @@
// definition is provided.
//===----------------------------------------------------------------------===//
#ifdef SANITIZER_DYNAMIC
-#include "sanitizer_win_weak_interception.h"
-#include "sanitizer_interface_internal.h"
-#include "sancov_flags.h"
+# include "sancov_flags.h"
+# include "sanitizer_interface_internal.h"
+# include "sanitizer_win_weak_interception.h"
// Check if strong definitions for weak functions are present in the main
// executable. If that is the case, override dll functions to point to strong
// implementations.
-#define INTERFACE_FUNCTION(Name)
-#define INTERFACE_WEAK_FUNCTION(Name) INTERCEPT_SANITIZER_WEAK_FUNCTION(Name)
-#include "coverage_sanitizer_interface.inc"
-#endif // SANITIZER_DYNAMIC
+# define INTERFACE_FUNCTION(Name)
+# define INTERFACE_WEAK_FUNCTION(Name) INTERCEPT_SANITIZER_WEAK_FUNCTION(Name)
+# include "coverage_sanitizer_interface.inc"
+#endif // SANITIZER_DYNAMIC
diff --git a/compiler-rt/test/asan/TestCases/Posix/coverage-reset.cpp b/compiler-rt/test/asan/TestCases/Posix/coverage-reset.cpp
index 8c3fd73e56..1ee66711d3 100644
--- a/compiler-rt/test/asan/TestCases/Posix/coverage-reset.cpp
+++ b/compiler-rt/test/asan/TestCases/Posix/coverage-reset.cpp
@@ -26,40 +26,40 @@ int main(int argc, char **argv) {
bar1();
bar2();
__sanitizer_cov_dump();
-// CHECK: RESET
-// CHECK-DAG: CoverageSanitizer: ./coverage-reset.cpp{{.*}}.sancov: 2 PCs written
-// CHECK-DAG: CoverageSanitizer: ./libcoverage-reset.cpp{{.*}}.sancov: 2 PCs written
+ // CHECK: RESET
+ // CHECK-DAG: CoverageSanitizer: ./coverage-reset.cpp{{.*}}.sancov: 2 PCs written
+ // CHECK-DAG: CoverageSanitizer: ./libcoverage-reset.cpp{{.*}}.sancov: 2 PCs written
fprintf(stderr, "RESET\n");
__sanitizer_cov_reset();
foo1();
bar1();
__sanitizer_cov_dump();
-// CHECK: RESET
-// CHECK-DAG: CoverageSanitizer: ./coverage-reset.cpp{{.*}}.sancov: 1 PCs written
-// CHECK-DAG: CoverageSanitizer: ./libcoverage-reset.cpp{{.*}}.sancov: 1 PCs written
+ // CHECK: RESET
+ // CHECK-DAG: CoverageSanitizer: ./coverage-reset.cpp{{.*}}.sancov: 1 PCs written
+ // CHECK-DAG: CoverageSanitizer: ./libcoverage-reset.cpp{{.*}}.sancov: 1 PCs written
fprintf(stderr, "RESET\n");
__sanitizer_cov_reset();
foo1();
foo2();
__sanitizer_cov_dump();
-// CHECK: RESET
-// CHECK: CoverageSanitizer: ./coverage-reset.cpp{{.*}}.sancov: 2 PCs written
+ // CHECK: RESET
+ // CHECK: CoverageSanitizer: ./coverage-reset.cpp{{.*}}.sancov: 2 PCs written
fprintf(stderr, "RESET\n");
__sanitizer_cov_reset();
bar1();
bar2();
__sanitizer_cov_dump();
-// CHECK: RESET
-// CHECK: CoverageSanitizer: ./libcoverage-reset.cpp{{.*}}.sancov: 2 PCs written
+ // CHECK: RESET
+ // CHECK: CoverageSanitizer: ./libcoverage-reset.cpp{{.*}}.sancov: 2 PCs written
fprintf(stderr, "RESET\n");
__sanitizer_cov_reset();
// CHECK: RESET
bar2();
-// CHECK: CoverageSanitizer: ./libcoverage-reset.cpp{{.*}}.sancov: 1 PCs written
+ // CHECK: CoverageSanitizer: ./libcoverage-reset.cpp{{.*}}.sancov: 1 PCs written
}
#endif
diff --git a/compiler-rt/test/sanitizer_common/TestCases/coverage_sanitizer_control_flow.cpp b/compiler-rt/test/sanitizer_common/TestCases/coverage_sanitizer_control_flow.cpp
index 5223af07f1..89622931c1 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/coverage_sanitizer_control_flow.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/coverage_sanitizer_control_flow.cpp
@@ -9,9 +9,9 @@
#include <cstdint>
#include <cstdio>
#if __has_feature(ptrauth_calls)
- #include <ptrauth.h>
+# include <ptrauth.h>
#else
- #define ptrauth_strip(__value, __key) (__value)
+# define ptrauth_strip(__value, __key) (__value)
#endif
uintptr_t *CFS_BEG, *CFS_END;
@@ -22,8 +22,7 @@ extern "C" void __sanitizer_cov_cfs_init(const uintptr_t *cfs_beg,
CFS_END = (uintptr_t *)cfs_end;
}
-__attribute__((noinline)) void foo(int x) { /* empty body */
-}
+__attribute__((noinline)) void foo(int x) { /* empty body */ }
void check_cfs_section(uintptr_t main_ptr, uintptr_t foo_ptr) {
printf("Control Flow section boundaries: [%p %p)\n", CFS_BEG, CFS_END);
diff --git a/compiler-rt/test/sanitizer_common/TestCases/coverage_sanitizer_inline8bit_counter.cpp b/compiler-rt/test/sanitizer_common/TestCases/coverage_sanitizer_inline8bit_counter.cpp
index 68eca85eb4..16c2d44514 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/coverage_sanitizer_inline8bit_counter.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/coverage_sanitizer_inline8bit_counter.cpp
@@ -6,14 +6,14 @@
// RUN: %clangxx -O0 %s -fsanitize-coverage=inline-8bit-counters,pc-table -o %t
// RUN: %run %t 2>&1 | FileCheck %s
-#include <stdio.h>
-#include <stdint.h>
#include <assert.h>
+#include <stdint.h>
+#include <stdio.h>
const char *first_counter;
-extern "C"
-void __sanitizer_cov_8bit_counters_init(const char *start, const char *end) {
+extern "C" void __sanitizer_cov_8bit_counters_init(const char *start,
+ const char *end) {
printf("INIT: %p %p\n", start, end);
assert(end - start > 1);
first_counter = start;
@@ -31,7 +31,6 @@ extern "C" void __sanitizer_cov_pcs_init(const uintptr_t *pcs_beg,
FirstPCFlag = B[1];
}
-
int main() {
assert(first_counter);
assert(*first_counter == 1);
diff --git a/compiler-rt/test/sanitizer_common/TestCases/coverage_sanitizer_stack_depth.cpp b/compiler-rt/test/sanitizer_common/TestCases/coverage_sanitizer_stack_depth.cpp
index 29a63c0a92..770c7d3497 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/coverage_sanitizer_stack_depth.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/coverage_sanitizer_stack_depth.cpp
@@ -6,9 +6,9 @@
// RUN: %s -o %t
// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not Assertion{{.*}}failed
+#include <cassert>
#include <cstdint>
#include <cstdio>
-#include <cassert>
thread_local uintptr_t __sancov_lowest_stack;
uintptr_t last_stack;
@@ -16,7 +16,8 @@ uintptr_t last_stack;
void foo(int recurse) {
assert(__sancov_lowest_stack < last_stack);
last_stack = __sancov_lowest_stack;
- if (recurse <= 0) return;
+ if (recurse <= 0)
+ return;
foo(recurse - 1);
}
diff --git a/compiler-rt/test/sanitizer_common/TestCases/coverage_sanitizer_trace_pc_guard-dso.cpp b/compiler-rt/test/sanitizer_common/TestCases/coverage_sanitizer_trace_pc_guard-dso.cpp
index a3911c099c..0bcfa9f96e 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/coverage_sanitizer_trace_pc_guard-dso.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/coverage_sanitizer_trace_pc_guard-dso.cpp
@@ -20,8 +20,8 @@
#include <stdio.h>
extern "C" {
- int bar();
- int baz();
+int bar();
+int baz();
}
#ifdef MAIN
diff --git a/compiler-rt/test/sanitizer_common/TestCases/coverage_sanitizer_trace_pc_guard-init.cpp b/compiler-rt/test/sanitizer_common/TestCases/coverage_sanitizer_trace_pc_guard-init.cpp
index cd5ea30713..8a9d24d285 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/coverage_sanitizer_trace_pc_guard-init.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/coverage_sanitizer_trace_pc_guard-init.cpp
@@ -11,23 +11,23 @@
// RUN: %env_tool_opts=coverage=1 %t 2>&1 | FileCheck %s
// RUN: rm -rf %t_workdir
-#include <stdio.h>
#include <stdint.h>
+#include <stdio.h>
#include <stdlib.h>
extern "C" {
- int bar();
- int baz();
+int bar();
+int baz();
}
#ifdef MAIN
-extern "C" void __sanitizer_cov_trace_pc_guard_init(uint32_t *start, uint32_t *stop) {
+extern "C" void __sanitizer_cov_trace_pc_guard_init(uint32_t *start,
+ uint32_t *stop) {
fprintf(stderr, "__sanitizer_cov_trace_pc_guard_init\n");
}
-extern "C" void __sanitizer_cov_trace_pc_guard(uint32_t *guard) { }
-
+extern "C" void __sanitizer_cov_trace_pc_guard(uint32_t *guard) {}
int foo() {
fprintf(stderr, "foo\n");
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index 46afb5c72b..c0b8274000 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -187,6 +187,7 @@
#include "llvm/Transforms/Instrumentation/BoundsChecking.h"
#include "llvm/Transforms/Instrumentation/CGProfile.h"
#include "llvm/Transforms/Instrumentation/ControlHeightReduction.h"
+#include "llvm/Transforms/Instrumentation/CoverageSanitizer.h"
#include "llvm/Transforms/Instrumentation/DataFlowSanitizer.h"
#include "llvm/Transforms/Instrumentation/GCOVProfiler.h"
#include "llvm/Transforms/Instrumentation/HWAddressSanitizer.h"
@@ -203,7 +204,6 @@
#include "llvm/Transforms/Instrumentation/PoisonChecking.h"
#include "llvm/Transforms/Instrumentation/RealtimeSanitizer.h"
#include "llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h"
-#include "llvm/Transforms/Instrumentation/CoverageSanitizer.h"
#include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
#include "llvm/Transforms/ObjCARC.h"
#include "llvm/Transforms/Scalar/ADCE.h"
diff --git a/llvm/lib/Transforms/Instrumentation/CoverageSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/CoverageSanitizer.cpp
index ff9157b806..648b9ee072 100644
--- a/llvm/lib/Transforms/Instrumentation/CoverageSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/CoverageSanitizer.cpp
@@ -272,11 +272,11 @@ private:
LLVMContext *C;
const DataLayout *DL;
- GlobalVariable *FunctionGuardArray; // for trace-pc-guard.
- GlobalVariable *Function8bitCounterArray; // for inline-8bit-counters.
- GlobalVariable *FunctionBoolArray; // for inline-bool-flag.
- GlobalVariable *FunctionPCsArray; // for pc-table.
- GlobalVariable *FunctionCFsArray; // for control flow table
+ GlobalVariable *FunctionGuardArray; // for trace-pc-guard.
+ GlobalVariable *Function8bitCounterArray; // for inline-8bit-counters.
+ GlobalVariable *FunctionBoolArray; // for inline-bool-flag.
+ GlobalVariable *FunctionPCsArray; // for pc-table.
+ GlobalVariable *FunctionCFsArray; // for control flow table
SmallVector<GlobalValue *, 20> GlobalsToAppendToUsed;
SmallVector<GlobalValue *, 20> GlobalsToAppendToCompilerUsed;
@@ -320,13 +320,11 @@ ModuleCoverageSanitizer::CreateSecStartEnd(Module &M, const char *Section,
GlobalValue::LinkageTypes Linkage = TargetTriple.isOSBinFormatCOFF()
? GlobalVariable::ExternalLinkage
: GlobalVariable::ExternalWeakLinkage;
- GlobalVariable *SecStart =
- new GlobalVariable(M, Ty, false, Linkage, nullptr,
- getSectionStart(Section));
+ GlobalVariable *SecStart = new GlobalVariable(M, Ty, false, Linkage, nullptr,
+ getSectionStart(Section));
SecStart->setVisibility(GlobalValue::HiddenVisibility);
- GlobalVariable *SecEnd =
- new GlobalVariable(M, Ty, false, Linkage, nullptr,
- getSectionEnd(Section));
+ GlobalVariable *SecEnd = new GlobalVariable(M, Ty, false, Linkage, nullptr,
+ getSectionEnd(Section));
SecEnd->setVisibility(GlobalValue::HiddenVisibility);
IRBuilder<> IRB(M.getContext());
if (!TargetTriple.isOSBinFormatCOFF())
@@ -432,25 +430,16 @@ bool ModuleCoverageSanitizer::instrumentModule() {
// Loads.
SanCovLoadFunction[0] = M.getOrInsertFunction(SanCovLoad1, VoidTy, PtrTy);
- SanCovLoadFunction[1] =
- M.getOrInsertFunction(SanCovLoad2, VoidTy, PtrTy);
- SanCovLoadFunction[2] =
- M.getOrInsertFunction(SanCovLoad4, VoidTy, PtrTy);
- SanCovLoadFunction[3] =
- M.getOrInsertFunction(SanCovLoad8, VoidTy, PtrTy);
- SanCovLoadFunction[4] =
- M.getOrInsertFunction(SanCovLoad16, VoidTy, PtrTy);
+ SanCovLoadFunction[1] = M.getOrInsertFunction(SanCovLoad2, VoidTy, PtrTy);
+ SanCovLoadFunction[2] = M.getOrInsertFunction(SanCovLoad4, VoidTy, PtrTy);
+ SanCovLoadFunction[3] = M.getOrInsertFunction(SanCovLoad8, VoidTy, PtrTy);
+ SanCovLoadFunction[4] = M.getOrInsertFunction(SanCovLoad16, VoidTy, PtrTy);
// Stores.
- SanCovStoreFunction[0] =
- M.getOrInsertFunction(SanCovStore1, VoidTy, PtrTy);
- SanCovStoreFunction[1] =
- M.getOrInsertFunction(SanCovStore2, VoidTy, PtrTy);
- SanCovStoreFunction[2] =
- M.getOrInsertFunction(SanCovStore4, VoidTy, PtrTy);
- SanCovStoreFunction[3] =
- M.getOrInsertFunction(SanCovStore8, VoidTy, PtrTy);
- SanCovStoreFunction[4] =
- M.getOrInsertFunction(SanCovStore16, VoidTy, PtrTy);
+ SanCovStoreFunction[0] = M.getOrInsertFunction(SanCovStore1, VoidTy, PtrTy);
+ SanCovStoreFunction[1] = M.getOrInsertFunction(SanCovStore2, VoidTy, PtrTy);
+ SanCovStoreFunction[2] = M.getOrInsertFunction(SanCovStore4, VoidTy, PtrTy);
+ SanCovStoreFunction[3] = M.getOrInsertFunction(SanCovStore8, VoidTy, PtrTy);
+ SanCovStoreFunction[4] = M.getOrInsertFunction(SanCovStore16, VoidTy, PtrTy);
{
AttributeList AL;
@@ -502,16 +491,16 @@ bool ModuleCoverageSanitizer::instrumentModule() {
}
if (Ctor && Options.PCTable) {
auto SecStartEnd = CreateSecStartEnd(M, SanCovPCsSectionName, IntptrTy);
- FunctionCallee InitFunction = declareSanitizerInitFunction(
- M, SanCovPCsInitName, {PtrTy, PtrTy});
+ FunctionCallee InitFunction =
+ declareSanitizerInitFunction(M, SanCovPCsInitName, {PtrTy, PtrTy});
IRBuilder<> IRBCtor(Ctor->getEntryBlock().getTerminator());
IRBCtor.CreateCall(InitFunction, {SecStartEnd.first, SecStartEnd.second});
}
if (Ctor && Options.CollectControlFlow) {
auto SecStartEnd = CreateSecStartEnd(M, SanCovCFsSectionName, IntptrTy);
- FunctionCallee InitFunction = declareSanitizerInitFunction(
- M, SanCovCFsInitName, {PtrTy, PtrTy});
+ FunctionCallee InitFunction =
+ declareSanitizerInitFunction(M, SanCovCFsInitName, {PtrTy, PtrTy});
IRBuilder<> IRBCtor(Ctor->getEntryBlock().getTerminator());
IRBCtor.CreateCall(InitFunction, {SecStartEnd.first, SecStartEnd.second});
}
@@ -568,8 +557,8 @@ static bool shouldInstrumentBlock(const Function &F, const BasicBlock *BB,
// Do not instrument full dominators, or full post-dominators with multiple
// predecessors.
- return !isFullDominator(BB, DT)
- && !(isFullPostDominator(BB, PDT) && !BB->getSinglePredecessor());
+ return !isFullDominator(BB, DT) &&
+ !(isFullPostDominator(BB, PDT) && !BB->getSinglePredecessor());
}
// Returns true iff From->To is a backedge.
@@ -740,16 +729,16 @@ ModuleCoverageSanitizer::CreatePCArray(Function &F,
for (size_t i = 0; i < N; i++) {
if (&F.getEntryBlock() == AllBlocks[i]) {
PCs.push_back((Constant *)IRB.CreatePointerCast(&F, PtrTy));
- PCs.push_back((Constant *)IRB.CreateIntToPtr(
- ConstantInt::get(IntptrTy, 1), PtrTy));
+ PCs.push_back(
+ (Constant *)IRB.CreateIntToPtr(ConstantInt::get(IntptrTy, 1), PtrTy));
} else {
PCs.push_back((Constant *)IRB.CreatePointerCast(
BlockAddress::get(AllBlocks[i]), PtrTy));
PCs.push_back(Constant::getNullValue(PtrTy));
}
}
- auto *PCArray = CreateFunctionLocalArrayInSection(N * 2, F, PtrTy,
- SanCovPCsSectionName);
+ auto *PCArray =
+ CreateFunctionLocalArrayInSection(N * 2, F, PtrTy, SanCovPCsSectionName);
PCArray->setInitializer(
ConstantArray::get(ArrayType::get(PtrTy, N * 2), PCs));
PCArray->setConstant(true);
@@ -777,7 +766,8 @@ void ModuleCoverageSanitizer::CreateFunctionLocalArrays(
bool ModuleCoverageSanitizer::InjectCoverage(Function &F,
ArrayRef<BasicBlock *> AllBlocks,
bool IsLeafFunc) {
- if (AllBlocks.empty()) return false;
+ if (AllBlocks.empty())
+ return false;
CreateFunctionLocalArrays(F, AllBlocks);
for (size_t i = 0, N = AllBlocks.size(); i < N; i++)
InjectCoverageAtBlock(F, *AllBlocks[i], i, IsLeafFunc);
@@ -853,13 +843,14 @@ void ModuleCoverageSanitizer::InjectTraceForDiv(
for (auto *BO : DivTraceTargets) {
InstrumentationIRBuilder IRB(BO);
Value *A1 = BO->getOperand(1);
- if (isa<ConstantInt>(A1)) continue;
+ if (isa<ConstantInt>(A1))
+ continue;
if (!A1->getType()->isIntegerTy())
continue;
uint64_t TypeSize = DL->getTypeStoreSizeInBits(A1->getType());
- int CallbackIdx = TypeSize == 32 ? 0 :
- TypeSize == 64 ? 1 : -1;
- if (CallbackIdx < 0) continue;
+ int CallbackIdx = TypeSize == 32 ? 0 : TypeSize == 64 ? 1 : -1;
+ if (CallbackIdx < 0)
+ continue;
auto Ty = Type::getIntNTy(*C, TypeSize);
IRB.CreateCall(SanCovTraceDivFunction[CallbackIdx],
{IRB.CreateIntCast(A1, Ty, true)});
@@ -916,17 +907,20 @@ void ModuleCoverageSanitizer::InjectTraceForCmp(
if (!A0->getType()->isIntegerTy())
continue;
uint64_t TypeSize = DL->getTypeStoreSizeInBits(A0->getType());
- int CallbackIdx = TypeSize == 8 ? 0 :
- TypeSize == 16 ? 1 :
- TypeSize == 32 ? 2 :
- TypeSize == 64 ? 3 : -1;
- if (CallbackIdx < 0) continue;
+ int CallbackIdx = TypeSize == 8 ? 0
+ : TypeSize == 16 ? 1
+ : TypeSize == 32 ? 2
+ : TypeSize == 64 ? 3
+ : -1;
+ if (CallbackIdx < 0)
+ continue;
// __sanitizer_cov_trace_cmp((type_size << 32) | predicate, A0, A1);
auto CallbackFunc = SanCovTraceCmpFunction[CallbackIdx];
bool FirstIsConst = isa<ConstantInt>(A0);
bool SecondIsConst = isa<ConstantInt>(A1);
// If both are const, then we don't need such a comparison.
- if (FirstIsConst && SecondIsConst) continue;
+ if (FirstIsConst && SecondIsConst)
+ continue;
// If only one is const, then make it the first callback argument.
if (FirstIsConst || SecondIsConst) {
CallbackFunc = SanCovTraceConstCmpFunction[CallbackIdx];
@@ -936,7 +930,7 @@ void ModuleCoverageSanitizer::InjectTraceForCmp(
auto Ty = Type::getIntNTy(*C, TypeSize);
IRB.CreateCall(CallbackFunc, {IRB.CreateIntCast(A0, Ty, true),
- IRB.CreateIntCast(A1, Ty, true)});
+ IRB.CreateIntCast(A1, Ty, true)});
}
}
}
@@ -1053,13 +1047,13 @@ void ModuleCoverageSanitizer::createFunctionControlFlow(Function &F) {
if (&BB == &F.getEntryBlock())
CFs.push_back((Constant *)IRB.CreatePointerCast(&F, PtrTy));
else
- CFs.push_back((Constant *)IRB.CreatePointerCast(BlockAddress::get(&BB),
- PtrTy));
+ CFs.push_back(
+ (Constant *)IRB.CreatePointerCast(BlockAddress::get(&BB), PtrTy));
for (auto SuccBB : successors(&BB)) {
assert(SuccBB != &F.getEntryBlock());
- CFs.push_back((Constant *)IRB.CreatePointerCast(BlockAddress::get(SuccBB),
- PtrTy));
+ CFs.push_back(
+ (Constant *)IRB.CreatePointerCast(BlockAddress::get(SuccBB), PtrTy));
}
CFs.push_back((Constant *)Constant::getNullValue(PtrTy));
@@ -1073,8 +1067,7 @@ void ModuleCoverageSanitizer::createFunctionControlFlow(Function &F) {
} else {
auto CalledF = CB->getCalledFunction();
if (CalledF && !CalledF->isIntrinsic())
- CFs.push_back(
- (Constant *)IRB.CreatePointerCast(CalledF, PtrTy));
+ CFs.push_back((Constant *)IRB.CreatePointerCast(CalledF, PtrTy));
}
}
}
@@ -1082,8 +1075,8 @@ void ModuleCoverageSanitizer::createFunctionControlFlow(Function &F) {
CFs.push_back((Constant *)Constant::getNullValue(PtrTy));
}
- FunctionCFsArray = CreateFunctionLocalArrayInSection(
- CFs.size(), F, PtrTy, SanCovCFsSectionName);
+ FunctionCFsArray = CreateFunctionLocalArrayInSection(CFs.size(), F, PtrTy,
+ SanCovCFsSectionName);
FunctionCFsArray->setInitializer(
ConstantArray::get(ArrayType::get(PtrTy, CFs.size()), CFs));
FunctionCFsArray->setConstant(true);
``````````
</details>
https://github.com/llvm/llvm-project/pull/106505
More information about the lldb-commits
mailing list