reader/spirv: Propagate errors during composite extraction

This prevents nullptr dereferences when invalid OpConstantComposite
instructions make it past spirv-val.

Fixed: chromium:1231650
Change-Id: Iddfe04dcfdce382096ae7dec7af8718b579f7951
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/61080
Auto-Submit: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
James Price 2021-08-06 20:31:59 +00:00 committed by Tint LUCI CQ
parent 1a1c42ef12
commit b2619443d9
2 changed files with 7 additions and 1 deletions

View File

@ -4399,6 +4399,10 @@ TypedExpression FunctionEmitter::MakeCompositeExtract(
auto composite_index = 0; auto composite_index = 0;
auto first_index_position = 1; auto first_index_position = 1;
TypedExpression current_expr(MakeOperand(inst, composite_index)); TypedExpression current_expr(MakeOperand(inst, composite_index));
if (!current_expr) {
return {};
}
const auto composite_id = inst.GetSingleWordInOperand(composite_index); const auto composite_id = inst.GetSingleWordInOperand(composite_index);
auto current_type_id = def_use_mgr_->GetDef(composite_id)->type_id(); auto current_type_id = def_use_mgr_->GetDef(composite_id)->type_id();
@ -4474,6 +4478,7 @@ TypedExpression FunctionEmitter::MakeCompositeValueDecomposition(
if (index_val >= kMaxVectorLen) { if (index_val >= kMaxVectorLen) {
Fail() << "internal error: swizzle index " << index_val Fail() << "internal error: swizzle index " << index_val
<< " is too big. Max handled index is " << kMaxVectorLen - 1; << " is too big. Max handled index is " << kMaxVectorLen - 1;
return {};
} }
next_expr = create<ast::MemberAccessorExpression>( next_expr = create<ast::MemberAccessorExpression>(
Source{}, current_expr.expr, Swizzle(index_val)); Source{}, current_expr.expr, Swizzle(index_val));

View File

@ -762,7 +762,8 @@ class FunctionEmitter {
/// Makes an expression from a SPIR-V ID. /// Makes an expression from a SPIR-V ID.
/// if the SPIR-V result type is a pointer. /// if the SPIR-V result type is a pointer.
/// @param id the SPIR-V ID of the value /// @param id the SPIR-V ID of the value
/// @returns true if emission has not yet failed. /// @returns an AST expression for the instruction, or an invalid
/// TypedExpression on error.
TypedExpression MakeExpression(uint32_t id); TypedExpression MakeExpression(uint32_t id);
/// Creates an expression and supporting statements for a combinatorial /// Creates an expression and supporting statements for a combinatorial