Add a test that exercises wrong usage of result id
authorEhsan Nasiri <ehsann@google.com>
Mon, 5 Dec 2016 19:00:18 +0000 (14:00 -0500)
committerDavid Neto <dneto@google.com>
Tue, 6 Dec 2016 14:50:08 +0000 (09:50 -0500)
Result <id> resulting from an instruction within a function may not be
used outside that function.

test/val/val_id_test.cpp

index b583f1a..11191b6 100644 (file)
@@ -2780,6 +2780,33 @@ TEST_F(ValidateIdWithMessage, OpStoreBitcastNonPointerBad) {
   EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
 }
 
+// Result <id> resulting from an instruction within a function may not be used
+// outside that function.
+TEST_F(ValidateIdWithMessage, ResultIdUsedOutsideOfFunctionBad) {
+  string spirv = kGLSL450MemoryModel + R"(
+%1 = OpTypeVoid
+%2 = OpTypeFunction %1
+%3 = OpTypeInt 32 0
+%4 = OpTypePointer Function %3
+%5 = OpFunction %1 None %2
+%6 = OpLabel
+%7 = OpVariable %4 Function
+OpReturn
+OpFunctionEnd
+%8 = OpFunction %1 None %2
+%9 = OpLabel
+%10 = OpLoad %3 %7
+OpReturn
+OpFunctionEnd
+  )";
+  CompileSuccessfully(spirv.c_str());
+  EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
+  EXPECT_THAT(
+      getDiagnosticString(),
+      HasSubstr(
+          "ID 7 defined in block 6 does not dominate its use in block 9"));
+}
+
 // TODO: OpLifetimeStart
 // TODO: OpLifetimeStop
 // TODO: OpAtomicInit