From a187e9e281254475088161ca906a905282f5663e Mon Sep 17 00:00:00 2001 From: James Price Date: Mon, 8 May 2023 17:48:30 +0000 Subject: [PATCH] spirv-reader: Error for OpSpecConstantComposite expression This is not currently supported, so produce a meaningful error message instead of crashing. Bug: oss-fuzz:55819 Bug: tint:111 Change-Id: Ib245a47edbbe6ef972844f940ea1d674e6b08a76 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/131222 Commit-Queue: James Price Reviewed-by: David Neto Kokoro: James Price --- src/tint/reader/spirv/function.cc | 6 ++++++ src/tint/reader/spirv/parser_impl.cc | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/tint/reader/spirv/function.cc b/src/tint/reader/spirv/function.cc index 45f6b35f4d..c3c12f2089 100644 --- a/src/tint/reader/spirv/function.cc +++ b/src/tint/reader/spirv/function.cc @@ -4075,6 +4075,12 @@ TypedExpression FunctionEmitter::EmitGlslStd450ExtInst(const spvtools::opt::Inst // All parameters to GLSL.std.450 extended instructions are IDs. for (uint32_t iarg = 2; iarg < inst.NumInOperands(); ++iarg) { TypedExpression operand = MakeOperand(inst, iarg); + if (!operand.expr) { + if (!failed()) { + Fail() << "unexpected failure to make an operand"; + } + return {}; + } if (first_operand_type == nullptr) { first_operand_type = operand.type; } diff --git a/src/tint/reader/spirv/parser_impl.cc b/src/tint/reader/spirv/parser_impl.cc index 6f6bf1e5a0..220ccb9f1e 100644 --- a/src/tint/reader/spirv/parser_impl.cc +++ b/src/tint/reader/spirv/parser_impl.cc @@ -1891,8 +1891,6 @@ TypedExpression ParserImpl::MakeConstantExpression(uint32_t id) { } auto source = GetSourceForInst(inst); - // TODO(dneto): Handle spec constants too? - auto* original_ast_type = ConvertType(inst->type_id()); if (original_ast_type == nullptr) { return {}; @@ -1952,6 +1950,12 @@ TypedExpression ParserImpl::MakeConstantExpression(uint32_t id) { declared_constant_composites_.insert({id, decl->name->symbol}); return {original_ast_type, builder_.Expr(name)}; } + case spv::Op::OpSpecConstantComposite: + case spv::Op::OpSpecConstantOp: { + // TODO(crbug.com/tint/111): Handle OpSpecConstantOp and OpSpecConstantComposite here. + Fail() << "unimplemented: OpSpecConstantOp and OpSpecConstantComposite"; + return {}; + } default: break; }