Handle id overflow in wrap-opkill (#2916)

New code in wrap-opkill does not handle id overflow correctly.  We fix that up.

Fixes https://crbug.com/1007144
This commit is contained in:
Steven Perron 2019-09-25 17:42:58 -04:00 committed by GitHub
parent 70097c7761
commit 2a11f365bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 2 deletions

View File

@ -60,13 +60,23 @@ bool WrapOpKill::ReplaceWithFunctionCall(Instruction* inst) {
return false;
}
Instruction* return_inst = nullptr;
uint32_t return_type_id = GetOwningFunctionsReturnType(inst);
if (return_type_id != GetVoidTypeId()) {
Instruction* undef = ir_builder.AddNullaryOp(return_type_id, SpvOpUndef);
ir_builder.AddUnaryOp(0, SpvOpReturnValue, undef->result_id());
if (undef == nullptr) {
return false;
}
return_inst =
ir_builder.AddUnaryOp(0, SpvOpReturnValue, undef->result_id());
} else {
ir_builder.AddNullaryOp(0, SpvOpReturn);
return_inst = ir_builder.AddNullaryOp(0, SpvOpReturn);
}
if (return_inst == nullptr) {
return false;
}
context()->KillInst(inst);
return true;
}

View File

@ -338,6 +338,46 @@ OpFunctionEnd
EXPECT_EQ(Pass::Status::Failure, std::get<1>(result));
}
TEST_F(WrapOpKillTest, IdBoundOverflow5) {
const std::string text = R"(
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %4 "main"
OpExecutionMode %4 OriginUpperLeft
OpDecorate %void Location 539091968
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%_struct_7 = OpTypeStruct %float %float
%_struct_8 = OpTypeStruct %_struct_7
%_ptr_Function__struct_8 = OpTypePointer Function %_struct_8
%_ptr_Output_float = OpTypePointer Output %float
%18 = OpTypeFunction %_struct_7 %_ptr_Function__struct_8
%4 = OpFunction %void Inline|Pure|Const %3
%850212 = OpLabel
%10 = OpVariable %_ptr_Function__struct_8 Function
%1441807 = OpFunctionCall %_struct_7 %32257 %10
OpKill
OpFunctionEnd
%32257 = OpFunction %_struct_7 None %18
%28 = OpLabel
OpUnreachable
OpFunctionEnd
%64821 = OpFunction %_struct_7 Inline %18
%4194295 = OpLabel
OpKill
OpFunctionEnd
)";
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
std::vector<Message> messages = {
{SPV_MSG_ERROR, "", 0, 0, "ID overflow. Try running compact-ids."}};
SetMessageConsumer(GetTestMessageConsumer(messages));
auto result = SinglePassRunToBinary<WrapOpKill>(text, true);
EXPECT_EQ(Pass::Status::Failure, std::get<1>(result));
}
} // namespace
} // namespace opt
} // namespace spvtools