From 1f6123fa5fc99af90cb04438479d2955ba7c3c3a Mon Sep 17 00:00:00 2001 From: Ehsan Nasiri Date: Mon, 5 Dec 2016 14:00:18 -0500 Subject: [PATCH] Add a test that exercises wrong usage of result id Result resulting from an instruction within a function may not be used outside that function. --- test/val/val_id_test.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/val/val_id_test.cpp b/test/val/val_id_test.cpp index b583f1a..11191b6 100644 --- a/test/val/val_id_test.cpp +++ b/test/val/val_id_test.cpp @@ -2780,6 +2780,33 @@ TEST_F(ValidateIdWithMessage, OpStoreBitcastNonPointerBad) { EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions()); } +// Result 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 -- 2.7.4