Fix EvalInt32IfConst to fail on type instructions.

Fixes https://crbug.com/875842

* EvalInt32IfConst dereferenced a null pointer if a type instruction was
sent as the id
diff --git a/source/val/validation_state.cpp b/source/val/validation_state.cpp
index c2b08e8..8fea3c6 100644
--- a/source/val/validation_state.cpp
+++ b/source/val/validation_state.cpp
@@ -862,7 +862,7 @@
   assert(inst);
   const uint32_t type = inst->type_id();
 
-  if (!IsIntScalarType(type) || GetBitWidth(type) != 32) {
+  if (type == 0 || !IsIntScalarType(type) || GetBitWidth(type) != 32) {
     return std::make_tuple(false, false, 0);
   }
 
diff --git a/test/val/val_barriers_test.cpp b/test/val/val_barriers_test.cpp
index 710504e..38c168e 100644
--- a/test/val/val_barriers_test.cpp
+++ b/test/val/val_barriers_test.cpp
@@ -804,6 +804,18 @@
                         "AcquireRelease or SequentiallyConsistent"));
 }
 
+TEST_F(ValidateBarriers, TypeAsMemoryScope) {
+  const std::string body = R"(
+OpMemoryBarrier %u32 %u32_0
+)";
+
+  CompileSuccessfully(GenerateKernelCode(body));
+  EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
+  EXPECT_THAT(
+      getDiagnosticString(),
+      HasSubstr("MemoryBarrier: expected Memory Scope to be a 32-bit int"));
+}
+
 }  // namespace
 }  // namespace val
 }  // namespace spvtools