From 58852aa012462a0a6da8391374943fd89bfc4151 Mon Sep 17 00:00:00 2001 From: Dejan Mircevski Date: Thu, 21 Jan 2016 09:00:15 -0500 Subject: [PATCH] Fix OpLoad pointee type validation. --- source/validate_id.cpp | 23 +++++++++++++++-------- test/ValidateID.cpp | 7 +++---- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/source/validate_id.cpp b/source/validate_id.cpp index 253ba83..1110fba 100644 --- a/source/validate_id.cpp +++ b/source/validate_id.cpp @@ -779,14 +779,21 @@ bool idUsage::isValid(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 '" << inst->words[resultTypeIndex] - << " does not match Pointer '" << 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 '" + << 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 '" + << inst->words[resultTypeIndex] + << "' does not match Pointer '" + << pointer.second.id << "'s type."; + return false; + } return true; } diff --git a/test/ValidateID.cpp b/test/ValidateID.cpp index 64930fb..e1a1d92 100644 --- a/test/ValidateID.cpp +++ b/test/ValidateID.cpp @@ -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 -- 2.7.4