mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-15 08:06:19 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user