Fixup line number for OpVectorShuffle ID error.

This CL updates the code to pull a valid instruction for the line number
when outputting a component error in OpVectorShuffle. The error line
isn't the best at this point as it points at the component, but it's
better then a -1 (turning to max<size_t>) that was being output.

The error messages has been updated to better reflect what the error is
attempting to say.

Issue 1719.
This commit is contained in:
Dan Sinclair 2018-07-16 10:53:46 -04:00 committed by David Neto
parent 208921efe8
commit 8c7dab5caa
2 changed files with 33 additions and 5 deletions

View File

@ -1781,9 +1781,9 @@ bool idUsage::isValid<SpvOpVectorShuffle>(const spv_instruction_t* inst,
for (size_t i = firstLiteralIndex; i < inst->words.size(); ++i) {
auto literal = inst->words[i];
if (literal != 0xFFFFFFFF && literal >= N) {
DIAG(module_.FindDef(inst->words[0]))
<< "Component literal value " << literal << " is greater than "
<< N - 1 << ".";
DIAG(module_.FindDef(inst->words[2]))
<< "Component index " << literal << " is out of range for a result "
<< "vector of size " << N << ".";
return false;
}
}

View File

@ -3848,8 +3848,10 @@ TEST_F(ValidateIdWithMessage, OpVectorShuffleLiterals) {
OpFunctionEnd)";
CompileSuccessfully(spirv.c_str());
EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
EXPECT_THAT(getDiagnosticString(),
HasSubstr("Component literal value 5 is greater than 4."));
EXPECT_THAT(
getDiagnosticString(),
HasSubstr(
"Component index 5 is out of range for a result vector of size 5."));
}
// TODO: OpCompositeConstruct
@ -4706,6 +4708,32 @@ OpFunctionEnd
EXPECT_EQ(SPV_SUCCESS, ValidateAndRetrieveValidationState());
}
TEST_F(ValidateIdWithMessage, CorrectErrorForShuffle) {
string spirv = kGLSL450MemoryModel + R"(
%uint = OpTypeInt 32 0
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%v2float = OpTypeVector %float 2
%void = OpTypeVoid
%548 = OpTypeFunction %void
%CS = OpFunction %void None %548
%550 = OpLabel
%6275 = OpUndef %v2float
%6280 = OpUndef %v2float
%6282 = OpVectorShuffle %v4float %6275 %6280 0 1 4 5
OpReturn
OpFunctionEnd
)";
CompileSuccessfully(spirv.c_str());
EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
EXPECT_THAT(
getDiagnosticString(),
HasSubstr(
"Component index 4 is out of range for a result vector of size 4."));
EXPECT_EQ(23, getErrorPosition().index);
}
// TODO: OpLifetimeStart
// TODO: OpLifetimeStop
// TODO: OpAtomicInit