validation: pointer to handle is not allowed

Bug: tint:986
Change-Id: Icce391c4741a2b9a090676fc5994a704941e4a30
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/58941
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
Sarah 2021-07-28 03:57:22 +00:00 committed by Sarah Mashayekhi
parent 3647df3fb7
commit edecbb161f
3 changed files with 35 additions and 3 deletions

View File

@ -2576,9 +2576,7 @@ fn via_call([[location(0)]] fragUV: vec2<f32>,
[[stage(fragment)]]
fn via_ptr([[location(0)]] fragUV: vec2<f32>,
[[location(1)]] fragPosition: vec4<f32>) -> [[location(0)]] vec4<f32> {
let t = &myTexture;
let s = &mySampler;
return textureSample(*t, *s, fragUV) + fragPosition;
return textureSample(myTexture, mySampler, fragUV) + fragPosition;
}
[[stage(fragment)]]

View File

@ -52,6 +52,34 @@ TEST_F(ResolverPtrRefValidationTest, AddressOfLet) {
EXPECT_EQ(r()->error(), "12:34 error: cannot take the address of expression");
}
TEST_F(ResolverPtrRefValidationTest, AddressOfHandle) {
// [[group(0), binding(0)]] var t: texture_3d<f32>;
// &t
Global("t", ty.sampled_texture(ast::TextureDimension::k3d, ty.f32()),
GroupAndBinding(0u, 0u));
auto* expr = AddressOf(Expr(Source{{12, 34}}, "t"));
WrapInFunction(expr);
EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(),
"12:34 error: cannot take the address of expression in handle "
"storage class");
}
TEST_F(ResolverPtrRefValidationTest, IndirectOfAddressOfHandle) {
// [[group(0), binding(0)]] var t: texture_3d<f32>;
// *&t
Global("t", ty.sampled_texture(ast::TextureDimension::k3d, ty.f32()),
GroupAndBinding(0u, 0u));
auto* expr = Deref(AddressOf(Expr(Source{{12, 34}}, "t")));
WrapInFunction(expr);
EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(),
"12:34 error: cannot take the address of expression in handle "
"storage class");
}
TEST_F(ResolverPtrRefValidationTest, DerefOfLiteral) {
// *1

View File

@ -3384,6 +3384,12 @@ bool Resolver::UnaryOp(ast::UnaryOpExpression* unary) {
case ast::UnaryOp::kAddressOf:
if (auto* ref = expr_type->As<sem::Reference>()) {
if (ref->StoreType()->UnwrapRef()->is_handle()) {
AddError(
"cannot take the address of expression in handle storage class",
unary->expr()->source());
return false;
}
type = builder_->create<sem::Pointer>(
ref->StoreType(), ref->StorageClass(), ref->Access());
} else {