Validator: Test OpReturnValue type check
authorDavid Neto <dneto@google.com>
Thu, 12 Oct 2017 19:20:29 +0000 (15:20 -0400)
committerDavid Neto <dneto@google.com>
Fri, 13 Oct 2017 19:19:13 +0000 (15:19 -0400)
The check already existed.  I added a test for it.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/876

test/val/val_id_test.cpp

index debc2e59a5552f7a1b8d5335cca5f2dd4d6ae9d9..5344b5a1a9ca5bb055c87ad44963a66271f8afe2 100644 (file)
@@ -2945,6 +2945,22 @@ TEST_F(ValidateIdWithMessage, OpFunctionResultTypeBad) {
               HasSubstr("OpFunction Result Type <id> '2' does not match the "
                         "Function Type <id> '2's return type."));
 }
+TEST_F(ValidateIdWithMessage, OpReturnValueTypeBad) {
+  string spirv = kGLSL450MemoryModel + R"(
+%1 = OpTypeInt 32 0
+%2 = OpTypeFloat 32
+%3 = OpConstant %2 0
+%4 = OpTypeFunction %1
+%5 = OpFunction %1 None %4
+%6 = OpLabel
+     OpReturnValue %3
+     OpFunctionEnd)";
+  CompileSuccessfully(spirv.c_str());
+  EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
+  EXPECT_THAT(getDiagnosticString(),
+              HasSubstr("OpReturnValue Value <id> '3's type does not match "
+                        "OpFunction's return type."));
+}
 TEST_F(ValidateIdWithMessage, OpFunctionFunctionTypeBad) {
   string spirv = kGLSL450MemoryModel + R"(
 %1 = OpTypeVoid