[dawn] Add DAWN_CHECK to stack_vec if absl doesn't provide it

Abseil in Chromium sets ABSL_OPTION_HARDENED but Google3 does not (yet).
Verified working as expected locally in both Dawn and Google3 builds.

Use an #if, rather than just adding it unconditionally, just in case
having a redundant check wouldn't get optimized out

Bug: none
Change-Id: I148c399647f0bc8c47f5a514d5edbcf525615640
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/260658
Auto-Submit: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: Loko Kung <lokokung@google.com>
Commit-Queue: Loko Kung <lokokung@google.com>
diff --git a/src/dawn/common/ityp_stack_vec.h b/src/dawn/common/ityp_stack_vec.h
index 45aa917..875a813 100644
--- a/src/dawn/common/ityp_stack_vec.h
+++ b/src/dawn/common/ityp_stack_vec.h
@@ -29,7 +29,6 @@
 #define SRC_DAWN_COMMON_ITYP_STACK_VEC_H_
 
 #include <limits>
-#include <vector>
 
 #include "absl/container/inlined_vector.h"
 #include "dawn/common/Assert.h"
@@ -48,10 +47,18 @@
     explicit stack_vec(Index size) : Base() { Base::resize(static_cast<I>(size)); }
 
     Value& operator[](Index i) {
+#if !defined(ABSL_OPTION_HARDENED) || ABSL_OPTION_HARDENED == 0
+        // Insert our own bounds check if not already enabled in absl
+        DAWN_CHECK(i < size());
+#endif
         return Base::operator[](static_cast<I>(i));
     }
 
     constexpr const Value& operator[](Index i) const {
+#if !defined(ABSL_OPTION_HARDENED) || ABSL_OPTION_HARDENED == 0
+        // Insert our own bounds check if not already enabled in absl
+        DAWN_CHECK(i < size());
+#endif
         return Base::operator[](static_cast<I>(i));
     }
 
@@ -60,7 +67,6 @@
     void reserve(Index size) { Base::reserve(static_cast<I>(size)); }
 
     Value* data() { return Base::data(); }
-
     const Value* data() const { return Base::data(); }
 
     Index size() const { return Index(static_cast<I>(Base::size())); }
diff --git a/src/dawn/tests/unittests/ITypStackVecTests.cpp b/src/dawn/tests/unittests/ITypStackVecTests.cpp
index a56268c..b982da5 100644
--- a/src/dawn/tests/unittests/ITypStackVecTests.cpp
+++ b/src/dawn/tests/unittests/ITypStackVecTests.cpp
@@ -73,7 +73,6 @@
     }
 
     StackVec vec(Key(10));
-
     EXPECT_DEATH(vec[Key(10)], "");
 
     const StackVec& constVec = vec;