tint/resolver: Fix null-deref.

Check the result of Materialize() for an index accessor.

Bug: chromium:1347541
Change-Id: Iac1b030a1923c96d65d531a0ca5fd1f4bd4271b9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/97851
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Auto-Submit: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Ben Clayton 2022-08-01 18:46:54 +00:00 committed by Dawn LUCI CQ
parent db5d2ea4f2
commit 4aa360db5d
2 changed files with 15 additions and 5 deletions

View File

@ -243,7 +243,7 @@ static std::ostream& operator<<(std::ostream& o, Method m) {
case Method::kWorkgroupSize: case Method::kWorkgroupSize:
return o << "workgroup-size"; return o << "workgroup-size";
case Method::kRuntimeIndex: case Method::kRuntimeIndex:
return o << "dynamic-index"; return o << "runtime-index";
} }
return o << "<unknown>"; return o << "<unknown>";
} }
@ -788,6 +788,9 @@ enum class Method {
// arr[abstract_expr] // arr[abstract_expr]
kIndex, kIndex,
// abstract_expr[runtime-index]
kRuntimeIndex,
}; };
static std::ostream& operator<<(std::ostream& o, Method m) { static std::ostream& operator<<(std::ostream& o, Method m) {
@ -810,6 +813,8 @@ static std::ostream& operator<<(std::ostream& o, Method m) {
return o << "workgroup-size"; return o << "workgroup-size";
case Method::kIndex: case Method::kIndex:
return o << "index"; return o << "index";
case Method::kRuntimeIndex:
return o << "runtime-index";
} }
return o << "<unknown>"; return o << "<unknown>";
} }
@ -895,6 +900,10 @@ TEST_P(MaterializeAbstractNumericToDefaultType, Test) {
GlobalVar("arr", ty.array<i32, 4>(), ast::StorageClass::kPrivate); GlobalVar("arr", ty.array<i32, 4>(), ast::StorageClass::kPrivate);
WrapInFunction(IndexAccessor("arr", abstract_expr())); WrapInFunction(IndexAccessor("arr", abstract_expr()));
break; break;
case Method::kRuntimeIndex:
auto* runtime_index = Var("runtime_index", nullptr, Expr(1_i));
WrapInFunction(runtime_index, IndexAccessor(abstract_expr(), runtime_index));
break;
} }
switch (expectation) { switch (expectation) {
@ -952,10 +961,8 @@ constexpr Method kAIntMethods[] = {
/// Methods that support vector materialization /// Methods that support vector materialization
constexpr Method kVectorMethods[] = { constexpr Method kVectorMethods[] = {
Method::kLet, Method::kLet, Method::kVar, Method::kBuiltinArg, Method::kBitcastVec3F32Arg,
Method::kVar, Method::kRuntimeIndex,
Method::kBuiltinArg,
Method::kBitcastVec3F32Arg,
}; };
/// Methods that support matrix materialization /// Methods that support matrix materialization

View File

@ -1434,6 +1434,9 @@ sem::Expression* Resolver::IndexAccessor(const ast::IndexAccessorExpression* exp
// vec2(1, 2)[runtime-index] // vec2(1, 2)[runtime-index]
obj = Materialize(obj); obj = Materialize(obj);
} }
if (!obj) {
return nullptr;
}
auto* obj_raw_ty = obj->Type(); auto* obj_raw_ty = obj->Type();
auto* obj_ty = obj_raw_ty->UnwrapRef(); auto* obj_ty = obj_raw_ty->UnwrapRef();
auto* ty = Switch( auto* ty = Switch(