tint/spriv-reader: emit error on non-finite literal
Bug: tint:1581 Bug: tint:1747 Change-Id: I2855c8e277e74ecf1465b81c4545b99fef2a321b Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/110701 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
003ed55ae5
commit
aff1656a76
|
@ -3966,7 +3966,11 @@ TypedExpression FunctionEmitter::MaybeEmitCombinatorialValue(
|
||||||
if (op == spv::Op::OpCompositeConstruct) {
|
if (op == spv::Op::OpCompositeConstruct) {
|
||||||
ExpressionList operands;
|
ExpressionList operands;
|
||||||
for (uint32_t iarg = 0; iarg < inst.NumInOperands(); ++iarg) {
|
for (uint32_t iarg = 0; iarg < inst.NumInOperands(); ++iarg) {
|
||||||
operands.Push(MakeOperand(inst, iarg).expr);
|
auto operand = MakeOperand(inst, iarg);
|
||||||
|
if (!operand) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
operands.Push(operand.expr);
|
||||||
}
|
}
|
||||||
return {ast_type,
|
return {ast_type,
|
||||||
builder_.Construct(Source{}, ast_type->Build(builder_), std::move(operands))};
|
builder_.Construct(Source{}, ast_type->Build(builder_), std::move(operands))};
|
||||||
|
|
|
@ -2025,10 +2025,15 @@ TypedExpression ParserImpl::MakeConstantExpressionForScalarSpirvConstant(
|
||||||
ast::IntLiteralExpression::Suffix::kU)};
|
ast::IntLiteralExpression::Suffix::kU)};
|
||||||
},
|
},
|
||||||
[&](const F32*) {
|
[&](const F32*) {
|
||||||
|
if (auto f = CheckedConvert<f32>(AFloat(spirv_const->GetFloat()))) {
|
||||||
return TypedExpression{ty_.F32(),
|
return TypedExpression{ty_.F32(),
|
||||||
create<ast::FloatLiteralExpression>(
|
create<ast::FloatLiteralExpression>(
|
||||||
source, static_cast<double>(spirv_const->GetFloat()),
|
source, static_cast<double>(spirv_const->GetFloat()),
|
||||||
ast::FloatLiteralExpression::Suffix::kF)};
|
ast::FloatLiteralExpression::Suffix::kF)};
|
||||||
|
} else {
|
||||||
|
Fail() << "value cannot be represented as 'f32': " << spirv_const->GetFloat();
|
||||||
|
return TypedExpression{};
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[&](const Bool*) {
|
[&](const Bool*) {
|
||||||
const bool value =
|
const bool value =
|
||||||
|
|
|
@ -217,5 +217,35 @@ TEST_F(SpvParserTest, Impl_IsValidIdentifier) {
|
||||||
EXPECT_TRUE(ParserImpl::IsValidIdentifier("x_")); // has underscore
|
EXPECT_TRUE(ParserImpl::IsValidIdentifier("x_")); // has underscore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(SpvParserTest, Impl_FailOnNonFiniteLiteral) {
|
||||||
|
auto spv = test::Assemble(R"(
|
||||||
|
OpCapability Shader
|
||||||
|
OpMemoryModel Logical GLSL450
|
||||||
|
OpEntryPoint Fragment %main "main" %out_var_SV_TARGET
|
||||||
|
OpExecutionMode %main OriginUpperLeft
|
||||||
|
OpSource HLSL 600
|
||||||
|
OpName %out_var_SV_TARGET "out.var.SV_TARGET"
|
||||||
|
OpName %main "main"
|
||||||
|
OpDecorate %out_var_SV_TARGET Location 0
|
||||||
|
%float = OpTypeFloat 32
|
||||||
|
%float_0x1p_128 = OpConstant %float -0x1p+128
|
||||||
|
%v4float = OpTypeVector %float 4
|
||||||
|
%_ptr_Output_v4float = OpTypePointer Output %v4float
|
||||||
|
%void = OpTypeVoid
|
||||||
|
%9 = OpTypeFunction %void
|
||||||
|
%out_var_SV_TARGET = OpVariable %_ptr_Output_v4float Output
|
||||||
|
%main = OpFunction %void None %9
|
||||||
|
%10 = OpLabel
|
||||||
|
%12 = OpCompositeConstruct %v4float %float_0x1p_128 %float_0x1p_128 %float_0x1p_128 %float_0x1p_128
|
||||||
|
OpStore %out_var_SV_TARGET %12
|
||||||
|
OpReturn
|
||||||
|
OpFunctionEnd
|
||||||
|
|
||||||
|
)");
|
||||||
|
auto p = parser(spv);
|
||||||
|
EXPECT_FALSE(p->Parse());
|
||||||
|
EXPECT_THAT(p->error(), HasSubstr("value cannot be represented as 'f32': -inf"));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace tint::reader::spirv
|
} // namespace tint::reader::spirv
|
||||||
|
|
Loading…
Reference in New Issue