[GWP-ASan] Fix unused variables from crash handler + clang-format

Summary: NFC - See title

Reviewers: eugenis

Reviewed By: eugenis

Subscribers: merge_guards_bot, #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D74100

GitOrigin-RevId: 0bfc4890931943388b6c9f5aae3d036668093c92
diff --git a/crash_handler.cpp b/crash_handler.cpp
index f287d02..c3b9e14 100644
--- a/crash_handler.cpp
+++ b/crash_handler.cpp
@@ -95,25 +95,21 @@
 }
 
 uintptr_t __gwp_asan_get_allocation_address(
-    const gwp_asan::AllocatorState *State,
     const gwp_asan::AllocationMetadata *AllocationMeta) {
   return AllocationMeta->Addr;
 }
 
 size_t __gwp_asan_get_allocation_size(
-    const gwp_asan::AllocatorState *State,
     const gwp_asan::AllocationMetadata *AllocationMeta) {
   return AllocationMeta->Size;
 }
 
 uint64_t __gwp_asan_get_allocation_thread_id(
-    const gwp_asan::AllocatorState *State,
     const gwp_asan::AllocationMetadata *AllocationMeta) {
   return AllocationMeta->AllocationTrace.ThreadID;
 }
 
 size_t __gwp_asan_get_allocation_trace(
-    const gwp_asan::AllocatorState *State,
     const gwp_asan::AllocationMetadata *AllocationMeta, uintptr_t *Buffer,
     size_t BufferLen) {
   return gwp_asan::compression::unpack(
@@ -122,19 +118,16 @@
 }
 
 bool __gwp_asan_is_deallocated(
-    const gwp_asan::AllocatorState *State,
     const gwp_asan::AllocationMetadata *AllocationMeta) {
   return AllocationMeta->IsDeallocated;
 }
 
 uint64_t __gwp_asan_get_deallocation_thread_id(
-    const gwp_asan::AllocatorState *State,
     const gwp_asan::AllocationMetadata *AllocationMeta) {
   return AllocationMeta->DeallocationTrace.ThreadID;
 }
 
 size_t __gwp_asan_get_deallocation_trace(
-    const gwp_asan::AllocatorState *State,
     const gwp_asan::AllocationMetadata *AllocationMeta, uintptr_t *Buffer,
     size_t BufferLen) {
   return gwp_asan::compression::unpack(
diff --git a/crash_handler.h b/crash_handler.h
index db9e864..631c319 100644
--- a/crash_handler.h
+++ b/crash_handler.h
@@ -73,19 +73,16 @@
 
 // Returns the start of the allocation whose metadata is in `AllocationMeta`.
 uintptr_t __gwp_asan_get_allocation_address(
-    const gwp_asan::AllocatorState *State,
     const gwp_asan::AllocationMetadata *AllocationMeta);
 
 // Returns the size of the allocation whose metadata is in `AllocationMeta`
 size_t __gwp_asan_get_allocation_size(
-    const gwp_asan::AllocatorState *State,
     const gwp_asan::AllocationMetadata *AllocationMeta);
 
 // Returns the Thread ID that allocated the memory that caused the error at
 // `ErrorPtr`. This function may not be called if __gwp_asan_has_metadata()
 // returns false.
 uint64_t __gwp_asan_get_allocation_thread_id(
-    const gwp_asan::AllocatorState *State,
     const gwp_asan::AllocationMetadata *AllocationMeta);
 
 // Retrieve the allocation trace for the allocation whose metadata is in
@@ -95,7 +92,6 @@
 // frames were stored by GWP-ASan). A return value greater than `BufferLen`
 // indicates that the trace was truncated when storing to `Buffer`.
 size_t __gwp_asan_get_allocation_trace(
-    const gwp_asan::AllocatorState *State,
     const gwp_asan::AllocationMetadata *AllocationMeta, uintptr_t *Buffer,
     size_t BufferLen);
 
@@ -103,14 +99,12 @@
 // deallocated. This function may not be called if __gwp_asan_has_metadata()
 // returns false.
 bool __gwp_asan_is_deallocated(
-    const gwp_asan::AllocatorState *State,
     const gwp_asan::AllocationMetadata *AllocationMeta);
 
 // Returns the Thread ID that deallocated the memory whose metadata is in
 // `AllocationMeta`. This function may not be called if
 // __gwp_asan_is_deallocated() returns false.
 uint64_t __gwp_asan_get_deallocation_thread_id(
-    const gwp_asan::AllocatorState *State,
     const gwp_asan::AllocationMetadata *AllocationMeta);
 
 // Retrieve the deallocation trace for the allocation whose metadata is in
@@ -121,7 +115,6 @@
 // indicates that the trace was truncated when storing to `Buffer`. This
 // function may not be called if __gwp_asan_is_deallocated() returns false.
 size_t __gwp_asan_get_deallocation_trace(
-    const gwp_asan::AllocatorState *State,
     const gwp_asan::AllocationMetadata *AllocationMeta, uintptr_t *Buffer,
     size_t BufferLen);
 
diff --git a/definitions.h b/definitions.h
index bebe56c..870dd96 100644
--- a/definitions.h
+++ b/definitions.h
@@ -9,7 +9,8 @@
 #ifndef GWP_ASAN_DEFINITIONS_H_
 #define GWP_ASAN_DEFINITIONS_H_
 
-#define GWP_ASAN_TLS_INITIAL_EXEC __thread __attribute__((tls_model("initial-exec")))
+#define GWP_ASAN_TLS_INITIAL_EXEC                                              \
+  __thread __attribute__((tls_model("initial-exec")))
 
 #define GWP_ASAN_UNLIKELY(X) __builtin_expect(!!(X), 0)
 #define GWP_ASAN_ALWAYS_INLINE inline __attribute__((always_inline))
diff --git a/guarded_pool_allocator.cpp b/guarded_pool_allocator.cpp
index cb8a183..4ce4d80 100644
--- a/guarded_pool_allocator.cpp
+++ b/guarded_pool_allocator.cpp
@@ -194,7 +194,7 @@
   State.FailureAddress = Address;
 
   // Raise a SEGV by touching first guard page.
-  volatile char *p = reinterpret_cast<char*>(State.GuardedPagePool);
+  volatile char *p = reinterpret_cast<char *>(State.GuardedPagePool);
   *p = 0;
   __builtin_unreachable();
 }
diff --git a/optional/segv_handler_posix.cpp b/optional/segv_handler_posix.cpp
index f98c16b..22589b8 100644
--- a/optional/segv_handler_posix.cpp
+++ b/optional/segv_handler_posix.cpp
@@ -72,7 +72,6 @@
 
 // Prints the provided error and metadata information.
 void printHeader(Error E, uintptr_t AccessPtr,
-                 const gwp_asan::AllocatorState *State,
                  const gwp_asan::AllocationMetadata *Metadata,
                  Printf_t Printf) {
   // Print using intermediate strings. Platforms like Android don't like when
@@ -81,9 +80,8 @@
   constexpr size_t kDescriptionBufferLen = 128;
   char DescriptionBuffer[kDescriptionBufferLen] = "";
   if (E != Error::UNKNOWN && Metadata != nullptr) {
-    uintptr_t Address =
-        __gwp_asan_get_allocation_address(State, Metadata);
-    size_t Size = __gwp_asan_get_allocation_size(State, Metadata);
+    uintptr_t Address = __gwp_asan_get_allocation_address(Metadata);
+    size_t Size = __gwp_asan_get_allocation_size(Metadata);
     if (E == Error::USE_AFTER_FREE) {
       snprintf(DescriptionBuffer, kDescriptionBufferLen,
                "(%zu byte%s into a %zu-byte allocation at 0x%zx) ",
@@ -191,7 +189,7 @@
       __gwp_asan_get_metadata(State, Metadata, ErrorPtr);
 
   // Print the error header.
-  printHeader(E, ErrorPtr, State, AllocMeta, Printf);
+  printHeader(E, ErrorPtr, AllocMeta, Printf);
 
   // Print the fault backtrace.
   static constexpr unsigned kMaximumStackFramesForCrashTrace = 512;
@@ -204,27 +202,25 @@
     return;
 
   // Maybe print the deallocation trace.
-  if (__gwp_asan_is_deallocated(State, AllocMeta)) {
-    uint64_t ThreadID =
-        __gwp_asan_get_deallocation_thread_id(State, AllocMeta);
+  if (__gwp_asan_is_deallocated(AllocMeta)) {
+    uint64_t ThreadID = __gwp_asan_get_deallocation_thread_id(AllocMeta);
     if (ThreadID == kInvalidThreadID)
       Printf("0x%zx was deallocated by thread <unknown> here:\n", ErrorPtr);
     else
       Printf("0x%zx was deallocated by thread %zu here:\n", ErrorPtr, ThreadID);
     TraceLength = __gwp_asan_get_deallocation_trace(
-        State, AllocMeta, Trace, kMaximumStackFramesForCrashTrace);
+        AllocMeta, Trace, kMaximumStackFramesForCrashTrace);
     PrintBacktrace(Trace, TraceLength, Printf);
   }
 
   // Print the allocation trace.
-  uint64_t ThreadID =
-      __gwp_asan_get_allocation_thread_id(State, AllocMeta);
+  uint64_t ThreadID = __gwp_asan_get_allocation_thread_id(AllocMeta);
   if (ThreadID == kInvalidThreadID)
     Printf("0x%zx was allocated by thread <unknown> here:\n", ErrorPtr);
   else
     Printf("0x%zx was allocated by thread %zu here:\n", ErrorPtr, ThreadID);
   TraceLength = __gwp_asan_get_allocation_trace(
-      State, AllocMeta, Trace, kMaximumStackFramesForCrashTrace);
+      AllocMeta, Trace, kMaximumStackFramesForCrashTrace);
   PrintBacktrace(Trace, TraceLength, Printf);
 }
 } // namespace crash_handler
diff --git a/tests/crash_handler_api.cpp b/tests/crash_handler_api.cpp
index 3df7ff5..10a014e 100644
--- a/tests/crash_handler_api.cpp
+++ b/tests/crash_handler_api.cpp
@@ -61,15 +61,14 @@
   void checkBacktrace(const AllocationMetadata *Meta, bool IsDeallocated) {
     uintptr_t Buffer[kNumBacktraceConstants];
     size_t NumBacktraceConstants = kNumBacktraceConstants;
-    EXPECT_EQ(NumBacktraceConstants,
-              __gwp_asan_get_allocation_trace(&State, Meta, Buffer,
-                                              kNumBacktraceConstants));
+    EXPECT_EQ(NumBacktraceConstants, __gwp_asan_get_allocation_trace(
+                                         Meta, Buffer, kNumBacktraceConstants));
     for (size_t i = 0; i < kNumBacktraceConstants; ++i)
       EXPECT_EQ(Buffer[i], BacktraceConstants[i]);
 
     if (IsDeallocated) {
       EXPECT_EQ(NumBacktraceConstants,
-                __gwp_asan_get_deallocation_trace(&State, Meta, Buffer,
+                __gwp_asan_get_deallocation_trace(Meta, Buffer,
                                                   kNumBacktraceConstants));
       for (size_t i = 0; i < kNumBacktraceConstants; ++i)
         EXPECT_EQ(Buffer[i], BacktraceConstants[i]);
@@ -80,14 +79,12 @@
     const AllocationMetadata *Meta =
         __gwp_asan_get_metadata(&State, Metadata, ErrorPtr);
     EXPECT_NE(nullptr, Meta);
-    EXPECT_EQ(Metadata[Index].Addr,
-              __gwp_asan_get_allocation_address(&State, Meta));
-    EXPECT_EQ(Metadata[Index].Size,
-              __gwp_asan_get_allocation_size(&State, Meta));
+    EXPECT_EQ(Metadata[Index].Addr, __gwp_asan_get_allocation_address(Meta));
+    EXPECT_EQ(Metadata[Index].Size, __gwp_asan_get_allocation_size(Meta));
     EXPECT_EQ(Metadata[Index].AllocationTrace.ThreadID,
-              __gwp_asan_get_allocation_thread_id(&State, Meta));
+              __gwp_asan_get_allocation_thread_id(Meta));
 
-    bool IsDeallocated = __gwp_asan_is_deallocated(&State, Meta);
+    bool IsDeallocated = __gwp_asan_is_deallocated(Meta);
     EXPECT_EQ(Metadata[Index].IsDeallocated, IsDeallocated);
     checkBacktrace(Meta, IsDeallocated);
 
@@ -95,7 +92,7 @@
       return;
 
     EXPECT_EQ(Metadata[Index].DeallocationTrace.ThreadID,
-              __gwp_asan_get_deallocation_thread_id(&State, Meta));
+              __gwp_asan_get_deallocation_thread_id(Meta));
   }
 
   static constexpr size_t kNumBacktraceConstants = 4;
diff --git a/tests/harness.h b/tests/harness.h
index 4bada14..e47254e 100644
--- a/tests/harness.h
+++ b/tests/harness.h
@@ -15,8 +15,8 @@
 
 #include "gwp_asan/guarded_pool_allocator.h"
 #include "gwp_asan/optional/backtrace.h"
-#include "gwp_asan/options.h"
 #include "gwp_asan/optional/segv_handler.h"
+#include "gwp_asan/options.h"
 
 namespace gwp_asan {
 namespace test {