From: David Neto Date: Mon, 13 Jun 2016 21:26:09 +0000 (-0400) Subject: In physical addressing, functions can return pointers X-Git-Tag: upstream/2018.6~1222 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3ed641df39c26c47dc06bd1f3044b9a32b5b9af5;p=platform%2Fupstream%2FSPIRV-Tools.git In physical addressing, functions can return pointers Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/229 --- diff --git a/source/validate_id.cpp b/source/validate_id.cpp index edb559b..2364b99 100644 --- a/source/validate_id.cpp +++ b/source/validate_id.cpp @@ -1710,12 +1710,11 @@ bool idUsage::isValid(const spv_instruction_t* inst, << value.second.type_id << "' is missing or void."; return false; } - if (SpvOpTypePointer == valueType.second.opcode) { - DIAG(valueIndex) << "OpReturnValue value's type '" - << value.second.type_id - << "' is a pointer, but a pointer can only be an operand " - "to OpLoad, OpStore, OpAccessChain, or " - "OpInBoundsAccessChain."; + if (addressingModel == SpvAddressingModelLogical && + SpvOpTypePointer == valueType.second.opcode) { + DIAG(valueIndex) + << "OpReturnValue value's type '" << value.second.type_id + << "' is a pointer, which is invalid in the Logical addressing model."; return false; } // NOTE: Find OpFunction diff --git a/test/ValidateID.cpp b/test/ValidateID.cpp index 6cff0ab..486f480 100644 --- a/test/ValidateID.cpp +++ b/test/ValidateID.cpp @@ -1564,8 +1564,26 @@ TEST_F(ValidateID, OpReturnValueIsVoid) { CHECK(spirv, SPV_ERROR_INVALID_ID); } -TEST_F(ValidateID, OpReturnValueIsVariable) { +TEST_F(ValidateID, OpReturnValueIsVariableInPhysical) { + // It's valid to return a pointer in a physical addressing model. const char* spirv = R"( + OpMemoryModel Physical32 OpenCL +%1 = OpTypeVoid +%2 = OpTypeInt 32 0 +%3 = OpTypePointer Private %2 +%4 = OpTypeFunction %3 +%5 = OpFunction %3 None %4 +%6 = OpLabel +%7 = OpVariable %3 Function + OpReturnValue %7 + OpFunctionEnd)"; + CHECK(spirv, SPV_SUCCESS); +} + +TEST_F(ValidateID, OpReturnValueIsVariableInLogical) { + // It's invalid to return a pointer in a physical addressing model. + const char* spirv = R"( + OpMemoryModel Logical GLSL450 %1 = OpTypeVoid %2 = OpTypeInt 32 0 %3 = OpTypePointer Private %2