BoundArrayAccessors: Don't share AST nodes
Each AST node must be unique. Having diamonds in the AST causes all sorts of exciting bugs in the resolver and later transforms. Bug: tint:469 Change-Id: I5dc43fef71a200632b3e8e8add77ec0537b01cd2 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46870 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
parent
b502fdf82b
commit
f23696ddda
|
@ -69,7 +69,12 @@ ast::ArrayAccessorExpression* BoundArrayAccessors::Transform(
|
|||
|
||||
if (size == 0) {
|
||||
if (is_arr) {
|
||||
auto* arr_len = b.Call("arrayLength", ctx->Clone(expr->array()));
|
||||
// Call Cloneable::Clone() instead of CloneContext::Clone() to ensure the
|
||||
// AST node is duplicated. CloneContext::Clone() will ensure that repeated
|
||||
// calls with the same pointer return the *same* cloned node - in this
|
||||
// case we actually want two copies.
|
||||
auto* arr = static_cast<ast::Expression*>(expr->array()->Clone(ctx));
|
||||
auto* arr_len = b.Call("arrayLength", arr);
|
||||
auto* limit = b.Sub(arr_len, b.Expr(1u));
|
||||
new_idx = b.Call("min", b.Construct<u32>(ctx->Clone(old_idx)), limit);
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue