[tint] Fix unsafe buffer usages in `spriv/reader`

Corrected issues in `ast_parser/function.cc` and added explainer
comment for suppressions that were due to an external header.

Bug: 394825124
Change-Id: I993a52dbae83d92f4d47919087b48e9854a0368c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/233116
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
diff --git a/src/tint/lang/spirv/reader/ast_parser/ast_parser.h b/src/tint/lang/spirv/reader/ast_parser/ast_parser.h
index f53f371..6f35357 100644
--- a/src/tint/lang/spirv/reader/ast_parser/ast_parser.h
+++ b/src/tint/lang/spirv/reader/ast_parser/ast_parser.h
@@ -39,6 +39,7 @@
 #include "src/tint/utils/macros/compiler.h"
 #include "src/tint/utils/text/string_stream.h"
 
+// This header is in an external dependency, so warnings cannot be fixed without upstream changes.
 TINT_BEGIN_DISABLE_WARNING(NEWLINE_EOF);
 TINT_BEGIN_DISABLE_WARNING(OLD_STYLE_CAST);
 TINT_BEGIN_DISABLE_WARNING(SIGN_CONVERSION);
diff --git a/src/tint/lang/spirv/reader/ast_parser/function.cc b/src/tint/lang/spirv/reader/ast_parser/function.cc
index 786b189..e655cba 100644
--- a/src/tint/lang/spirv/reader/ast_parser/function.cc
+++ b/src/tint/lang/spirv/reader/ast_parser/function.cc
@@ -157,13 +157,14 @@
 using namespace tint::core::number_suffixes;  // NOLINT
 using namespace tint::core::fluent_types;     // NOLINT
 
-TINT_BEGIN_DISABLE_WARNING(UNSAFE_BUFFER_USAGE);
 
 namespace tint::spirv::reader::ast_parser {
 namespace {
 
 constexpr uint32_t kMaxVectorLen = 4;
 
+static constexpr std::array<const char*, 4> kComponentNames = {"x", "y", "z", "w"};
+
 /// @param inst a SPIR-V instruction
 /// @returns Returns the opcode for an instruciton
 inline spv::Op opcode(const spvtools::opt::Instruction& inst) {
@@ -4329,8 +4330,7 @@
         Fail() << "vector component index is larger than " << kMaxVectorLen - 1 << ": " << i;
         return nullptr;
     }
-    const char* names[] = {"x", "y", "z", "w"};
-    return builder_.Ident(names[i & 3]);
+    return builder_.Ident(kComponentNames[i & 3]);
 }
 
 const ast::Identifier* FunctionEmitter::PrefixSwizzle(uint32_t n) {
@@ -4738,9 +4738,8 @@
 
     // Helper to get the name for the component index `i`.
     auto component_name = [](uint32_t i) {
-        constexpr const char* names[] = {"x", "y", "z", "w"};
         TINT_ASSERT(i < 4);
-        return names[i];
+        return kComponentNames[i];
     };
 
     // Build a swizzle for each consecutive set of indices that fall within the same vector.
@@ -5303,7 +5302,7 @@
 }
 
 bool FunctionEmitter::EmitControlBarrier(const spvtools::opt::Instruction& inst) {
-    uint32_t operands[3];
+    std::array<uint32_t, 3> operands;
     for (uint32_t i = 0; i < 3; i++) {
         auto id = inst.GetSingleWordInOperand(i);
         if (auto* constant = constant_mgr_->FindDeclaredConstant(id)) {
@@ -6475,5 +6474,3 @@
 TINT_INSTANTIATE_TYPEINFO(tint::spirv::reader::ast_parser::SwitchStatementBuilder);
 TINT_INSTANTIATE_TYPEINFO(tint::spirv::reader::ast_parser::IfStatementBuilder);
 TINT_INSTANTIATE_TYPEINFO(tint::spirv::reader::ast_parser::LoopStatementBuilder);
-
-TINT_BEGIN_DISABLE_WARNING(UNSAFE_BUFFER_USAGE);
diff --git a/src/tint/lang/spirv/reader/ast_parser/helper_test.h b/src/tint/lang/spirv/reader/ast_parser/helper_test.h
index 5fe1e86..636478d 100644
--- a/src/tint/lang/spirv/reader/ast_parser/helper_test.h
+++ b/src/tint/lang/spirv/reader/ast_parser/helper_test.h
@@ -36,6 +36,7 @@
 
 #include "src/tint/utils/macros/compiler.h"
 
+// This header is in an external dependency, so warnings cannot be fixed without upstream changes.
 TINT_BEGIN_DISABLE_WARNING(NEWLINE_EOF);
 TINT_BEGIN_DISABLE_WARNING(OLD_STYLE_CAST);
 TINT_BEGIN_DISABLE_WARNING(SIGN_CONVERSION);
diff --git a/src/tint/lang/spirv/reader/parser/parser.cc b/src/tint/lang/spirv/reader/parser/parser.cc
index 162abe9..3ab9666 100644
--- a/src/tint/lang/spirv/reader/parser/parser.cc
+++ b/src/tint/lang/spirv/reader/parser/parser.cc
@@ -36,6 +36,7 @@
 #include <utility>
 #include <vector>
 
+// This header is in an external dependency, so warnings cannot be fixed without upstream changes.
 TINT_BEGIN_DISABLE_WARNING(NEWLINE_EOF);
 TINT_BEGIN_DISABLE_WARNING(OLD_STYLE_CAST);
 TINT_BEGIN_DISABLE_WARNING(SIGN_CONVERSION);