Change abseil hardening assertions in chunked_queue and fixed_array from macros to functions

This associates debug information with the assertion sites,
allowing clearer stack-traces for assertion failures and
better accounting of the performance overhead of assertions.

PiperOrigin-RevId: 911422559
Change-Id: Ifce3fd62685173c6b2f83c4c4e4c97c152a463b1
diff --git a/absl/container/BUILD.bazel b/absl/container/BUILD.bazel
index 65081ee..a43213c 100644
--- a/absl/container/BUILD.bazel
+++ b/absl/container/BUILD.bazel
@@ -71,6 +71,7 @@
         "//absl/base:config",
         "//absl/base:core_headers",
         "//absl/base:dynamic_annotations",
+        "//absl/base:hardening",
         "//absl/base:iterator_traits_internal",
         "//absl/base:throw_delegate",
         "//absl/hash:weakly_mixed_integer",
@@ -1367,6 +1368,7 @@
         ":layout",
         "//absl/base:config",
         "//absl/base:core_headers",
+        "//absl/base:hardening",
         "//absl/base:iterator_traits_internal",
     ],
 )
diff --git a/absl/container/CMakeLists.txt b/absl/container/CMakeLists.txt
index 983d187..a1ce8a3 100644
--- a/absl/container/CMakeLists.txt
+++ b/absl/container/CMakeLists.txt
@@ -129,6 +129,7 @@
     absl::config
     absl::core_headers
     absl::dynamic_annotations
+    absl::hardening
     absl::iterator_traits_internal
     absl::throw_delegate
     absl::memory
@@ -1214,6 +1215,7 @@
   DEPS
      absl::config
      absl::core_headers
+     absl::hardening
      absl::iterator_traits_internal
      absl::layout
 )
diff --git a/absl/container/chunked_queue.h b/absl/container/chunked_queue.h
index d5b1184..ff81447 100644
--- a/absl/container/chunked_queue.h
+++ b/absl/container/chunked_queue.h
@@ -107,6 +107,7 @@
 
 #include "absl/base/attributes.h"
 #include "absl/base/config.h"
+#include "absl/base/internal/hardening.h"
 #include "absl/base/internal/iterator_traits.h"
 #include "absl/base/macros.h"
 #include "absl/container/internal/chunked_queue.h"
@@ -428,22 +429,22 @@
   // Returns a reference to the first element in the container.
   // REQUIRES: !empty()
   T& front() {
-    ABSL_HARDENING_ASSERT(!empty());
+    absl::base_internal::HardeningAssertNonEmpty(*this);
     return *head_;
   }
   const T& front() const {
-    ABSL_HARDENING_ASSERT(!empty());
+    absl::base_internal::HardeningAssertNonEmpty(*this);
     return *head_;
   }
 
   // Returns a reference to the last element in the container.
   // REQUIRES: !empty()
   T& back() {
-    ABSL_HARDENING_ASSERT(!empty());
+    absl::base_internal::HardeningAssertNonEmpty(*this);
     return *(&*tail_ - 1);
   }
   const T& back() const {
-    ABSL_HARDENING_ASSERT(!empty());
+    absl::base_internal::HardeningAssertNonEmpty(*this);
     return *(&*tail_ - 1);
   }
 
@@ -460,7 +461,8 @@
       // (It is undefined behavior to swap between two containers with unequal
       // allocators if propagate_on_container_swap is false, so we don't have to
       // handle that here like we do in the move-assignment operator.)
-      ABSL_HARDENING_ASSERT(get_allocator() == other.get_allocator());
+      absl::base_internal::HardeningAssert(get_allocator() ==
+                                           other.get_allocator());
       swap(alloc_and_size_.size, other.alloc_and_size_.size);
     }
   }
@@ -709,7 +711,7 @@
 
 template <typename T, size_t BLo, size_t BHi, typename Allocator>
 inline void chunked_queue<T, BLo, BHi, Allocator>::pop_front() {
-  ABSL_HARDENING_ASSERT(!empty());
+  absl::base_internal::HardeningAssertNonEmpty(*this);
   ABSL_ASSERT(head_.block);
   AllocatorTraits::destroy(alloc_and_size_.allocator(), head_.ptr);
   ++head_.ptr;
diff --git a/absl/container/fixed_array.h b/absl/container/fixed_array.h
index e6f1528..77949bf 100644
--- a/absl/container/fixed_array.h
+++ b/absl/container/fixed_array.h
@@ -44,6 +44,7 @@
 #include "absl/base/attributes.h"
 #include "absl/base/config.h"
 #include "absl/base/dynamic_annotations.h"
+#include "absl/base/internal/hardening.h"
 #include "absl/base/internal/iterator_traits.h"
 #include "absl/base/macros.h"
 #include "absl/base/optimization.h"
@@ -222,7 +223,7 @@
   // Returns a reference the ith element of the fixed array.
   // REQUIRES: 0 <= i < size()
   reference operator[](size_type i) ABSL_ATTRIBUTE_LIFETIME_BOUND {
-    ABSL_HARDENING_ASSERT(i < size());
+    absl::base_internal::HardeningAssertLT(i, size());
     return data()[i];
   }
 
@@ -230,7 +231,7 @@
   // ith element of the fixed array.
   // REQUIRES: 0 <= i < size()
   const_reference operator[](size_type i) const ABSL_ATTRIBUTE_LIFETIME_BOUND {
-    ABSL_HARDENING_ASSERT(i < size());
+    absl::base_internal::HardeningAssertLT(i, size());
     return data()[i];
   }
 
@@ -258,14 +259,14 @@
   //
   // Returns a reference to the first element of the fixed array.
   reference front() ABSL_ATTRIBUTE_LIFETIME_BOUND {
-    ABSL_HARDENING_ASSERT(!empty());
+    absl::base_internal::HardeningAssertNonEmpty(*this);
     return data()[0];
   }
 
   // Overload of FixedArray::front() to return a reference to the first element
   // of a fixed array of const values.
   const_reference front() const ABSL_ATTRIBUTE_LIFETIME_BOUND {
-    ABSL_HARDENING_ASSERT(!empty());
+    absl::base_internal::HardeningAssertNonEmpty(*this);
     return data()[0];
   }
 
@@ -273,14 +274,14 @@
   //
   // Returns a reference to the last element of the fixed array.
   reference back() ABSL_ATTRIBUTE_LIFETIME_BOUND {
-    ABSL_HARDENING_ASSERT(!empty());
+    absl::base_internal::HardeningAssertNonEmpty(*this);
     return data()[size() - 1];
   }
 
   // Overload of FixedArray::back() to return a reference to the last element
   // of a fixed array of const values.
   const_reference back() const ABSL_ATTRIBUTE_LIFETIME_BOUND {
-    ABSL_HARDENING_ASSERT(!empty());
+    absl::base_internal::HardeningAssertNonEmpty(*this);
     return data()[size() - 1];
   }