In physical addressing, functions can return pointers

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/229
This commit is contained in:
David Neto 2016-06-13 17:26:09 -04:00
parent 10dba91781
commit 3ed641df39
2 changed files with 24 additions and 7 deletions

View File

@ -1710,12 +1710,11 @@ bool idUsage::isValid<SpvOpReturnValue>(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 <id> '"
<< 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 <id> '" << value.second.type_id
<< "' is a pointer, which is invalid in the Logical addressing model.";
return false;
}
// NOTE: Find OpFunction

View File

@ -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