Only check def dominance of reachable uses

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/295
This commit is contained in:
David Neto 2016-08-04 14:57:09 -04:00
parent 50707a1257
commit 621fa3961f
3 changed files with 40 additions and 0 deletions

View File

@ -13,6 +13,7 @@ v2016.2-dev 2016-07-19
#279: validator: infinite loop when analyzing some degenerate control
flow graphs
#290: disassembler: never generate bare % for an identifier
#295: validator: def-use dominance check should ignore unreachable uses
v2016.1 2016-07-19
- Fix https://github.com/KhronosGroup/SPIRV-Tools/issues/261

View File

@ -2392,6 +2392,7 @@ spv_result_t CheckIdDefinitionDominateUse(const ValidationState_t& _) {
// If the Id is defined within a block then make sure all references to
// that Id appear in a blocks that are dominated by the defining block
for (auto use : definition.second.uses()) {
if (!use->reachable()) continue;
if (use->dom_end() == find(use->dom_begin(), use->dom_end(), block)) {
return _.diag(SPV_ERROR_INVALID_ID)
<< "ID " << _.getIdName(definition.first)

View File

@ -1234,6 +1234,44 @@ TEST_F(ValidateSSA, DISABLED_PhiVariableDefMustComeFromBlockDominatingThePredece
// TODO(dneto): Check for a good error message
}
TEST_F(ValidateSSA, DominanceCheckIgnoresUsesInUnreachableBlocksDefInBlockGood) {
string str = kHeader
+ kBasicTypes +
R"(
%func = OpFunction %voidt None %vfunct
%entry = OpLabel
%def = OpCopyObject %boolt %false
OpReturn
%unreach = OpLabel
%use = OpCopyObject %boolt %def
OpReturn
OpFunctionEnd
)";
CompileSuccessfully(str);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions()) << getDiagnosticString();
}
TEST_F(ValidateSSA, DominanceCheckIgnoresUsesInUnreachableBlocksDefIsParamGood) {
string str = kHeader + kBasicTypes +
R"(
%void_fn_int = OpTypeFunction %voidt %intt
%func = OpFunction %voidt None %void_fn_int
%int_param = OpFunctionParameter %intt
%entry = OpLabel
OpReturn
%unreach = OpLabel
%use = OpCopyObject %intt %int_param
OpReturn
OpFunctionEnd
)";
CompileSuccessfully(str);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions()) << getDiagnosticString();
}
TEST_F(ValidateSSA, UseFunctionParameterFromOtherFunctionBad) {
string str = kHeader +
"OpName %first \"first\"\n"