Fix OpLoad pointee type validation.

This commit is contained in:
Dejan Mircevski 2016-01-21 09:00:15 -05:00 committed by David Neto
parent c62f41e281
commit 58852aa012
2 changed files with 18 additions and 12 deletions

View File

@ -779,14 +779,21 @@ bool idUsage::isValid<SpvOpLoad>(const spv_instruction_t* inst,
<< "' is not a pointer.";
return false;
}
auto type = usedefs_.FindDef(pointer.second.words[1]);
assert(type.first);
spvCheck(resultType.second.id != type.second.id,
DIAG(resultTypeIndex)
<< "OpLoad Result Type <id> '" << inst->words[resultTypeIndex]
<< " does not match Pointer <id> '" << pointer.second.id
<< "'s type.";
return false);
auto pointerType = usedefs_.FindDef(pointer.second.words[1]);
if (!pointerType.first || pointerType.second.opcode != SpvOpTypePointer) {
DIAG(pointerIndex) << "OpLoad type for pointer <id> '"
<< inst->words[pointerIndex]
<< "' is not a pointer type.";
return false;
}
auto pointeeType = usedefs_.FindDef(pointerType.second.words[3]);
if (!pointeeType.first || resultType.second.id != pointeeType.second.id) {
DIAG(resultTypeIndex) << "OpLoad Result Type <id> '"
<< inst->words[resultTypeIndex]
<< "' does not match Pointer <id> '"
<< pointer.second.id << "'s type.";
return false;
}
return true;
}

View File

@ -694,7 +694,7 @@ TEST_F(ValidateID, OpLoadGood) {
%5 = OpVariable %3 UniformConstant
%6 = OpFunction %1 None %4
%7 = OpLabel
%8 = OpLoad %3 %5
%8 = OpLoad %2 %5
%9 = OpReturn
%10 = OpFunctionEnd
)";
@ -709,7 +709,7 @@ TEST_F(ValidateID, OpLoadResultTypeBad) {
%5 = OpVariable %3 UniformConstant
%6 = OpFunction %1 None %4
%7 = OpLabel
%8 = OpLoad %2 %5
%8 = OpLoad %3 %5
OpReturn
OpFunctionEnd
)";
@ -1015,8 +1015,7 @@ TEST_F(ValidateID, OpFunctionCallGood) {
%6 = OpFunction %2 None %3
%7 = OpFunctionParameter %2
%8 = OpLabel
%9 = OpLoad %2 %7
OpReturnValue %9
OpReturnValue %7
OpFunctionEnd
%10 = OpFunction %1 None %4