Disallow taking the address of a vector component

Update or remove tests that try to do this.

Fixed: tint:491
Change-Id: I1f351a4abf68ae9bc6b100885fb1bcea08b31211
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/68242
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
James Price
2021-11-04 19:55:57 +00:00
parent def9d97609
commit 85170d76bc
18 changed files with 87 additions and 231 deletions

View File

@@ -66,6 +66,34 @@ TEST_F(ResolverPtrRefValidationTest, AddressOfHandle) {
"storage class");
}
TEST_F(ResolverPtrRefValidationTest, AddressOfVectorComponent_MemberAccessor) {
// var v : vec4<i32>;
// &v.y
auto* v = Var("v", ty.vec4<i32>());
auto* expr = AddressOf(MemberAccessor(Source{{12, 34}}, "v", "y"));
WrapInFunction(v, expr);
EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(),
"12:34 error: cannot take the address of a vector component");
}
TEST_F(ResolverPtrRefValidationTest, AddressOfVectorComponent_ArrayAccessor) {
// var v : vec4<i32>;
// &v[2]
auto* v = Var("v", ty.vec4<i32>());
auto* expr = AddressOf(IndexAccessor(Source{{12, 34}}, "v", 2));
WrapInFunction(v, expr);
EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(),
"12:34 error: cannot take the address of a vector component");
}
TEST_F(ResolverPtrRefValidationTest, IndirectOfAddressOfHandle) {
// [[group(0), binding(0)]] var t: texture_3d<f32>;
// *&t

View File

@@ -3428,6 +3428,17 @@ bool Resolver::UnaryOp(const ast::UnaryOpExpression* unary) {
unary->expr->source);
return false;
}
auto* array = unary->expr->As<ast::ArrayAccessorExpression>();
auto* member = unary->expr->As<ast::MemberAccessorExpression>();
if ((array && TypeOf(array->array)->UnwrapRef()->Is<sem::Vector>()) ||
(member &&
TypeOf(member->structure)->UnwrapRef()->Is<sem::Vector>())) {
AddError("cannot take the address of a vector component",
unary->expr->source);
return false;
}
type = builder_->create<sem::Pointer>(
ref->StoreType(), ref->StorageClass(), ref->Access());
} else {