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>
diff --git a/src/inspector/inspector_test.cc b/src/inspector/inspector_test.cc
index 9e43df5..6a886d8 100644
--- a/src/inspector/inspector_test.cc
+++ b/src/inspector/inspector_test.cc
@@ -2576,9 +2576,7 @@
[[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)]]
diff --git a/src/resolver/ptr_ref_validation_test.cc b/src/resolver/ptr_ref_validation_test.cc
index 73b1f46..59e7b44 100644
--- a/src/resolver/ptr_ref_validation_test.cc
+++ b/src/resolver/ptr_ref_validation_test.cc
@@ -52,6 +52,34 @@
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
diff --git a/src/resolver/resolver.cc b/src/resolver/resolver.cc
index a395cd8..b980b96 100644
--- a/src/resolver/resolver.cc
+++ b/src/resolver/resolver.cc
@@ -3384,6 +3384,12 @@
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 {