Remove asserts from GetUnderlyingType (#2646)

Fixes #2463
diff --git a/source/val/validate_builtins.cpp b/source/val/validate_builtins.cpp
index b476e78..bcd691f 100644
--- a/source/val/validate_builtins.cpp
+++ b/source/val/validate_builtins.cpp
@@ -60,12 +60,22 @@
                                const Instruction& inst,
                                uint32_t* underlying_type) {
   if (decoration.struct_member_index() != Decoration::kInvalidMember) {
-    assert(inst.opcode() == SpvOpTypeStruct);
+    if (inst.opcode() != SpvOpTypeStruct) {
+      return _.diag(SPV_ERROR_INVALID_DATA, &inst)
+             << GetIdDesc(inst)
+             << "Attempted to get underlying data type via member index for "
+                "non-struct type.";
+    }
     *underlying_type = inst.word(decoration.struct_member_index() + 2);
     return SPV_SUCCESS;
   }
 
-  assert(inst.opcode() != SpvOpTypeStruct);
+  if (inst.opcode() == SpvOpTypeStruct) {
+    return _.diag(SPV_ERROR_INVALID_DATA, &inst)
+           << GetIdDesc(inst)
+           << " did not find an member index to get underlying data type for "
+              "struct type.";
+  }
 
   if (spvOpcodeIsConstant(inst.opcode())) {
     *underlying_type = inst.type_id();
diff --git a/test/val/val_builtins_test.cpp b/test/val/val_builtins_test.cpp
index c8b2188..cff9d4a 100644
--- a/test/val/val_builtins_test.cpp
+++ b/test/val/val_builtins_test.cpp
@@ -2864,6 +2864,33 @@
   EXPECT_THAT(getDiagnosticString(), HasSubstr("is not an int scalar"));
 }
 
+TEST_F(ValidateBuiltIns, GetUnderlyingTypeNoAssert) {
+  std::string spirv = R"(
+                      OpCapability Shader
+                      OpMemoryModel Logical GLSL450
+                      OpEntryPoint Fragment %4 "PSMa" %12 %17
+                      OpExecutionMode %4 OriginUpperLeft
+                      OpDecorate %gl_PointCoord BuiltIn PointCoord
+              %void = OpTypeVoid
+                 %3 = OpTypeFunction %void
+             %float = OpTypeFloat 32
+           %v4float = OpTypeVector %float 4
+       %gl_PointCoord = OpTypeStruct %v4float
+       %_ptr_Input_v4float = OpTypePointer Input %v4float
+       %_ptr_Output_v4float = OpTypePointer Output %v4float
+                %12 = OpVariable %_ptr_Input_v4float Input
+                %17 = OpVariable %_ptr_Output_v4float Output
+                 %4 = OpFunction %void None %3
+                %15 = OpLabel
+                      OpReturn
+                      OpFunctionEnd)";
+  CompileSuccessfully(spirv, SPV_ENV_VULKAN_1_1);
+  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_1));
+  EXPECT_THAT(getDiagnosticString(),
+              HasSubstr("did not find an member index to get underlying data "
+                        "type"));
+}
+
 }  // namespace
 }  // namespace val
 }  // namespace spvtools