mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-05 12:46:11 +00:00
tint: Use resolved source var in LocalizeStructArrayAssignment
Fixed: tint:1341 Change-Id: Ic88623bd5891d3d7d32400825e02122c36102803 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/87607 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
parent
98eb169692
commit
a9d8da4434
@ -68,40 +68,25 @@ class LocalizeStructArrayAssignment::State {
|
|||||||
std::pair<const sem::Type*, ast::StorageClass>
|
std::pair<const sem::Type*, ast::StorageClass>
|
||||||
GetOriginatingTypeAndStorageClass(
|
GetOriginatingTypeAndStorageClass(
|
||||||
const ast::AssignmentStatement* assign_stmt) {
|
const ast::AssignmentStatement* assign_stmt) {
|
||||||
// Get first IdentifierExpr from lhs of assignment, which should resolve to
|
auto* source_var = ctx.src->Sem().Get(assign_stmt->lhs)->SourceVariable();
|
||||||
// the pointer or reference of the originating variable of the assignment.
|
if (!source_var) {
|
||||||
// TraverseExpressions traverses left to right, and this code depends on the
|
|
||||||
// fact that for an assignment statement, the variable will be the left-most
|
|
||||||
// expression.
|
|
||||||
// TODO(crbug.com/tint/1341): do this in the Resolver, setting the
|
|
||||||
// originating variable on sem::Expression.
|
|
||||||
const ast::IdentifierExpression* ident = nullptr;
|
|
||||||
ast::TraverseExpressions(assign_stmt->lhs, b.Diagnostics(),
|
|
||||||
[&](const ast::IdentifierExpression* id) {
|
|
||||||
ident = id;
|
|
||||||
return ast::TraverseAction::Stop;
|
|
||||||
});
|
|
||||||
auto* sem_var_user = ctx.src->Sem().Get<sem::VariableUser>(ident);
|
|
||||||
if (!sem_var_user) {
|
|
||||||
TINT_ICE(Transform, b.Diagnostics())
|
TINT_ICE(Transform, b.Diagnostics())
|
||||||
<< "Expected to find variable of lhs of assignment statement";
|
<< "Unable to determine originating variable for lhs of assignment "
|
||||||
|
"statement";
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* var = sem_var_user->Variable();
|
auto* type = source_var->Type();
|
||||||
if (auto* ptr = var->Type()->As<sem::Pointer>()) {
|
if (auto* ref = type->As<sem::Reference>()) {
|
||||||
|
return {ref->StoreType(), ref->StorageClass()};
|
||||||
|
} else if (auto* ptr = type->As<sem::Pointer>()) {
|
||||||
return {ptr->StoreType(), ptr->StorageClass()};
|
return {ptr->StoreType(), ptr->StorageClass()};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* ref = var->Type()->As<sem::Reference>();
|
TINT_ICE(Transform, b.Diagnostics())
|
||||||
if (!ref) {
|
<< "Expecting to find variable of type pointer or reference on lhs "
|
||||||
TINT_ICE(Transform, b.Diagnostics())
|
"of assignment statement";
|
||||||
<< "Expecting to find variable of type pointer or reference on lhs "
|
return {};
|
||||||
"of assignment statement";
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {ref->StoreType(), ref->StorageClass()};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user