Validation function pointer type information.
This CL updates the resolver to validate that parameters to functions do
not have invalid pointer types.
Bug: tint:2215
Change-Id: Ieab35d4c5400dc9c575d3ad41220f2b1da963c4c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/181980
Auto-Submit: dan sinclair <dsinclair@chromium.org>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: James Price <jrprice@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
diff --git a/src/tint/lang/wgsl/resolver/resolver_test.cc b/src/tint/lang/wgsl/resolver/resolver_test.cc
index 3d21f7a..58c6f8f 100644
--- a/src/tint/lang/wgsl/resolver/resolver_test.cc
+++ b/src/tint/lang/wgsl/resolver/resolver_test.cc
@@ -31,6 +31,7 @@
#include "gmock/gmock.h"
#include "gtest/gtest-spi.h"
+#include "src/tint/lang/core/address_space.h"
#include "src/tint/lang/core/builtin_value.h"
#include "src/tint/lang/core/type/reference.h"
#include "src/tint/lang/core/type/sampled_texture.h"
@@ -2419,7 +2420,7 @@
});
ASSERT_FALSE(r()->Resolve());
- EXPECT_EQ(r()->error(), "error: cannot take the address of 'var s' in handle address space");
+ EXPECT_EQ(r()->error(), "error: pointer can not be formed to a sampler");
}
TEST_F(ResolverTest, ModuleDependencyOrderedDeclarations) {
@@ -2743,5 +2744,123 @@
EXPECT_EQ(r()->error(), "12:34 error: array has nesting depth of 256, maximum is 255");
}
+TEST_F(ResolverTest, PointerToHandleTextureParameter) {
+ Func("helper",
+ Vector{
+ Param("sl", ty.ptr<function>(
+ Source{{12, 34}},
+ ty.sampled_texture(core::type::TextureDimension::k1d, ty.f32()))),
+ },
+ ty.void_(), {});
+
+ EXPECT_FALSE(r()->Resolve());
+ EXPECT_EQ(r()->error(), "12:34 error: pointer can not be formed to a texture");
+}
+
+TEST_F(ResolverTest, PointerToHandleTextureReturn) {
+ Func("helper", {},
+ ty.ptr<function>(Source{{12, 34}},
+ ty.sampled_texture(core::type::TextureDimension::k1d, ty.f32())),
+ {});
+
+ EXPECT_FALSE(r()->Resolve());
+ EXPECT_EQ(r()->error(), "12:34 error: pointer can not be formed to a texture");
+}
+
+TEST_F(ResolverTest, PointerToHandleSamplerParameter) {
+ Func("helper",
+ Vector{
+ Param("sl", ty.ptr<function>(Source{{12, 34}},
+ ty.sampler(core::type::SamplerKind::kSampler))),
+ },
+ ty.void_(), {});
+
+ EXPECT_FALSE(r()->Resolve());
+ EXPECT_EQ(r()->error(), "12:34 error: pointer can not be formed to a sampler");
+}
+
+TEST_F(ResolverTest, PointerToHandleTextureParameterAlias) {
+ auto* my_ty = Alias(
+ "MyTy", ty.ptr<private_>(Source{{12, 34}},
+ ty.sampled_texture(core::type::TextureDimension::k1d, ty.f32())));
+ Func("helper",
+ Vector{
+ Param("sl", ty.Of(my_ty)),
+ },
+ ty.void_(), {});
+
+ EXPECT_FALSE(r()->Resolve());
+ EXPECT_EQ(r()->error(), "12:34 error: pointer can not be formed to a texture");
+}
+
+TEST_F(ResolverTest, PointerToHandleSamplerParameterAlias) {
+ auto* my_ty = Alias(
+ "MyTy", ty.ptr<private_>(Source{{12, 34}}, ty.sampler(core::type::SamplerKind::kSampler)));
+ Func("helper",
+ Vector{
+ Param("sl", ty.Of(my_ty)),
+ },
+ ty.void_(), {});
+
+ EXPECT_FALSE(r()->Resolve());
+ EXPECT_EQ(r()->error(), "12:34 error: pointer can not be formed to a sampler");
+}
+
+TEST_F(ResolverTest, PointerToHandleTextureVar) {
+ GlobalVar("s",
+ ty.ptr<private_>(Source{{12, 34}},
+ ty.sampled_texture(core::type::TextureDimension::k1d, ty.f32())),
+ core::AddressSpace::kPrivate, Group(0_a), Binding(0_a));
+
+ EXPECT_FALSE(r()->Resolve());
+ EXPECT_EQ(r()->error(), "12:34 error: pointer can not be formed to a texture");
+}
+
+TEST_F(ResolverTest, PointerToHandleSamplerVar) {
+ GlobalVar("s",
+ ty.ptr<private_>(Source{{12, 34}}, ty.sampler(core::type::SamplerKind::kSampler)),
+ Group(0_a), core::AddressSpace::kPrivate, Binding(0_a));
+
+ EXPECT_FALSE(r()->Resolve());
+ EXPECT_EQ(r()->error(), "12:34 error: pointer can not be formed to a sampler");
+}
+
+TEST_F(ResolverTest, PointerToHandleTextureVarAlias) {
+ auto* my_ty = Alias(
+ "MyTy", ty.ptr<private_>(Source{{12, 34}},
+ ty.sampled_texture(core::type::TextureDimension::k1d, ty.f32())));
+ GlobalVar("s", ty.Of(my_ty), core::AddressSpace::kPrivate, Group(0_a), Binding(0_a));
+
+ EXPECT_FALSE(r()->Resolve());
+ EXPECT_EQ(r()->error(), "12:34 error: pointer can not be formed to a texture");
+}
+
+TEST_F(ResolverTest, PointerToHandleSamplerVarAlias) {
+ auto* my_ty = Alias(
+ "MyTy", ty.ptr<private_>(Source{{12, 34}}, ty.sampler(core::type::SamplerKind::kSampler)));
+
+ GlobalVar("s", ty.Of(my_ty), Group(0_a), core::AddressSpace::kPrivate, Binding(0_a));
+
+ EXPECT_FALSE(r()->Resolve());
+ EXPECT_EQ(r()->error(), "12:34 error: pointer can not be formed to a sampler");
+}
+
+TEST_F(ResolverTest, PointerToHandleTextureAlias) {
+ Alias("MyTy",
+ ty.ptr<private_>(Source{{12, 34}},
+ ty.sampled_texture(core::type::TextureDimension::k1d, ty.f32())));
+
+ EXPECT_FALSE(r()->Resolve());
+ EXPECT_EQ(r()->error(), "12:34 error: pointer can not be formed to a texture");
+}
+
+TEST_F(ResolverTest, PointerToHandleSamplerAlias) {
+ Alias("MyTy",
+ ty.ptr<private_>(Source{{12, 34}}, ty.sampler(core::type::SamplerKind::kSampler)));
+
+ EXPECT_FALSE(r()->Resolve());
+ EXPECT_EQ(r()->error(), "12:34 error: pointer can not be formed to a sampler");
+}
+
} // namespace
} // namespace tint::resolver
diff --git a/src/tint/lang/wgsl/resolver/validator.cc b/src/tint/lang/wgsl/resolver/validator.cc
index a7a42ec..1c110f8 100644
--- a/src/tint/lang/wgsl/resolver/validator.cc
+++ b/src/tint/lang/wgsl/resolver/validator.cc
@@ -339,6 +339,16 @@
return false;
}
+ if (s->AddressSpace() != core::AddressSpace::kHandle) {
+ if (s->StoreType()->Is<core::type::Texture>()) {
+ AddError(a->source) << "pointer can not be formed to a texture";
+ return false;
+ } else if (s->StoreType()->Is<core::type::Sampler>()) {
+ AddError(a->source) << "pointer can not be formed to a sampler";
+ return false;
+ }
+ }
+
if (a->arguments.Length() > 2) { // ptr<address-space, type [, access]>
// https://www.w3.org/TR/WGSL/#access-mode-defaults
// When writing a variable declaration or a pointer type in WGSL source:
diff --git a/webgpu-cts/expectations.txt b/webgpu-cts/expectations.txt
index d4f37a7..464b299 100644
--- a/webgpu-cts/expectations.txt
+++ b/webgpu-cts/expectations.txt
@@ -1761,31 +1761,6 @@
crbug.com/dawn/0000 [ dawn-no-backend-validation nvidia-0x2184 target-cpu-64 webgpu-adapter-default webgpu-dxc-disabled win10 ] webgpu:shader,execution,statement,discard:derivatives: [ Failure ]
crbug.com/dawn/0000 [ dawn-no-backend-validation nvidia-0x2184 target-cpu-64 webgpu-adapter-default webgpu-dxc-enabled win10 ] webgpu:shader,execution,statement,discard:derivatives: [ Failure ]
crbug.com/dawn/0000 [ dawn-no-backend-validation nvidia-0x2184 target-cpu-64 webgpu-adapter-default webgpu-dxc-enabled win10 ] webgpu:shader,execution,zero_init:compute,zero_init:addressSpace="private";workgroupSize=[1,1,1];batch__=11 [ Failure ]
-crbug.com/dawn/0000 [ amd-0x67ef dawn-backend-validation target-cpu-64 ventura webgpu-adapter-default ] webgpu:shader,validation,functions,restrictions:function_parameter_types:case="invalid_ptr8" [ Failure ]
-crbug.com/dawn/0000 [ amd-0x67ef dawn-no-backend-validation target-cpu-64 ventura webgpu-adapter-default ] webgpu:shader,validation,functions,restrictions:function_parameter_types:case="invalid_ptr8" [ Failure ]
-crbug.com/dawn/0000 [ android-r dawn-backend-validation qualcomm target-cpu-32 webgpu-adapter-default ] webgpu:shader,validation,functions,restrictions:function_parameter_types:case="invalid_ptr8" [ Failure ]
-crbug.com/dawn/0000 [ android-r dawn-no-backend-validation qualcomm target-cpu-32 webgpu-adapter-default ] webgpu:shader,validation,functions,restrictions:function_parameter_types:case="invalid_ptr8" [ Failure ]
-crbug.com/dawn/0000 [ android-t arm dawn-backend-validation target-cpu-64 webgpu-adapter-default ] webgpu:shader,validation,functions,restrictions:function_parameter_types:case="invalid_ptr8" [ Failure ]
-crbug.com/dawn/0000 [ android-t arm dawn-no-backend-validation target-cpu-64 webgpu-adapter-default ] webgpu:shader,validation,functions,restrictions:function_parameter_types:case="invalid_ptr8" [ Failure ]
-crbug.com/dawn/0000 [ apple-angle-metal-renderer:-apple-m2 dawn-backend-validation target-cpu-64 ventura webgpu-adapter-default ] webgpu:shader,validation,functions,restrictions:function_parameter_types:case="invalid_ptr8" [ Failure ]
-crbug.com/dawn/0000 [ apple-angle-metal-renderer:-apple-m2 dawn-no-backend-validation target-cpu-64 ventura webgpu-adapter-default ] webgpu:shader,validation,functions,restrictions:function_parameter_types:case="invalid_ptr8" [ Failure ]
-crbug.com/dawn/0000 [ dawn-backend-validation intel-0x3e9b sonoma target-cpu-64 webgpu-adapter-default ] webgpu:shader,validation,functions,restrictions:function_parameter_types:case="invalid_ptr8" [ Failure ]
-crbug.com/dawn/0000 [ dawn-backend-validation intel-0x3e9b target-cpu-64 ventura webgpu-adapter-default ] webgpu:shader,validation,functions,restrictions:function_parameter_types:case="invalid_ptr8" [ Failure ]
-crbug.com/dawn/0000 [ dawn-backend-validation intel-0x9bc5 target-cpu-64 ubuntu webgpu-adapter-default ] webgpu:shader,validation,functions,restrictions:function_parameter_types:case="invalid_ptr8" [ Failure ]
-crbug.com/dawn/0000 [ dawn-backend-validation intel-0x9bc5 target-cpu-64 webgpu-adapter-default webgpu-dxc-disabled win10 ] webgpu:shader,validation,functions,restrictions:function_parameter_types:case="invalid_ptr8" [ Failure ]
-crbug.com/dawn/0000 [ dawn-backend-validation nvidia-0x2184 target-cpu-64 ubuntu webgpu-adapter-default ] webgpu:shader,validation,functions,restrictions:function_parameter_types:case="invalid_ptr8" [ Failure ]
-crbug.com/dawn/0000 [ dawn-backend-validation nvidia-0x2184 target-cpu-64 webgpu-adapter-default webgpu-dxc-disabled win10 ] webgpu:shader,validation,functions,restrictions:function_parameter_types:case="invalid_ptr8" [ Failure ]
-crbug.com/dawn/0000 [ dawn-backend-validation nvidia-0x2184 target-cpu-64 webgpu-adapter-default webgpu-dxc-enabled win10 ] webgpu:shader,validation,functions,restrictions:function_parameter_types:case="invalid_ptr8" [ Failure ]
-crbug.com/dawn/0000 [ dawn-no-backend-validation intel-0x3e9b sonoma target-cpu-64 webgpu-adapter-default ] webgpu:shader,validation,functions,restrictions:function_parameter_types:case="invalid_ptr8" [ Failure ]
-crbug.com/dawn/0000 [ dawn-no-backend-validation intel-0x3e9b target-cpu-64 ventura webgpu-adapter-default ] webgpu:shader,validation,functions,restrictions:function_parameter_types:case="invalid_ptr8" [ Failure ]
-crbug.com/dawn/0000 [ dawn-no-backend-validation intel-0x9bc5 target-cpu-64 ubuntu webgpu-adapter-default ] webgpu:shader,validation,functions,restrictions:function_parameter_types:case="invalid_ptr8" [ Failure ]
-crbug.com/dawn/0000 [ dawn-no-backend-validation intel-0x9bc5 target-cpu-32 webgpu-adapter-default webgpu-dxc-disabled win10 ] webgpu:shader,validation,functions,restrictions:function_parameter_types:case="invalid_ptr8" [ Failure ]
-crbug.com/dawn/0000 [ dawn-no-backend-validation intel-0x9bc5 target-cpu-64 webgpu-adapter-default webgpu-dxc-disabled win10 ] webgpu:shader,validation,functions,restrictions:function_parameter_types:case="invalid_ptr8" [ Failure ]
-crbug.com/dawn/0000 [ dawn-no-backend-validation intel-0x9bc5 target-cpu-64 webgpu-adapter-default webgpu-dxc-enabled win10 ] webgpu:shader,validation,functions,restrictions:function_parameter_types:case="invalid_ptr8" [ Failure ]
-crbug.com/dawn/0000 [ dawn-no-backend-validation nvidia-0x2184 target-cpu-64 ubuntu webgpu-adapter-default ] webgpu:shader,validation,functions,restrictions:function_parameter_types:case="invalid_ptr8" [ Failure ]
-crbug.com/dawn/0000 [ dawn-no-backend-validation nvidia-0x2184 target-cpu-32 webgpu-adapter-default webgpu-dxc-disabled win10 ] webgpu:shader,validation,functions,restrictions:function_parameter_types:case="invalid_ptr8" [ Failure ]
-crbug.com/dawn/0000 [ dawn-no-backend-validation nvidia-0x2184 target-cpu-64 webgpu-adapter-default webgpu-dxc-disabled win10 ] webgpu:shader,validation,functions,restrictions:function_parameter_types:case="invalid_ptr8" [ Failure ]
-crbug.com/dawn/0000 [ dawn-no-backend-validation nvidia-0x2184 target-cpu-64 webgpu-adapter-default webgpu-dxc-enabled win10 ] webgpu:shader,validation,functions,restrictions:function_parameter_types:case="invalid_ptr8" [ Failure ]
crbug.com/dawn/0000 [ dawn-backend-validation intel-0x3e9b sonoma webgpu-adapter-swiftshader ] webgpu:web_platform,canvas,readbackFromWebGPUCanvas:onscreenCanvas,uploadToWebGL:format="bgra8unorm";alphaMode="premultiplied";webgl="webgl";upload="texSubImage2D" [ Failure ]
crbug.com/dawn/0000 [ dawn-no-backend-validation intel-0x3e9b sonoma webgpu-adapter-default ] webgpu:web_platform,canvas,readbackFromWebGPUCanvas:onscreenCanvas,uploadToWebGL:format="rgba16float";alphaMode="opaque";webgl="webgl";upload="texSubImage2D" [ Failure ]
crbug.com/dawn/0000 [ dawn-backend-validation intel-0x3e9b sonoma webgpu-adapter-swiftshader ] webgpu:web_platform,canvas,readbackFromWebGPUCanvas:onscreenCanvas,uploadToWebGL:format="rgba16float";alphaMode="premultiplied";webgl="webgl";upload="texSubImage2D" [ Failure ]