validation: cannot cast to a pointer
Bug: tint:73 Change-Id: I913509b4d5bd502c7699364db4e7a02f8895cc58 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/54760 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Ben Clayton <bclayton@google.com> Commit-Queue: Ben Clayton <bclayton@google.com> Auto-Submit: Sarah Mashayekhi <sarahmashay@google.com>
This commit is contained in:
parent
d47eb3a965
commit
4b1c9de503
|
@ -12,6 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
#include "src/ast/bitcast_expression.h"
|
||||||
#include "src/ast/struct_block_decoration.h"
|
#include "src/ast/struct_block_decoration.h"
|
||||||
#include "src/resolver/resolver.h"
|
#include "src/resolver/resolver.h"
|
||||||
#include "src/resolver/resolver_test_helper.h"
|
#include "src/resolver/resolver_test_helper.h"
|
||||||
|
@ -114,6 +115,19 @@ TEST_F(ResolverPtrRefValidationTest, InferredPtrAccessMismatch) {
|
||||||
"'ptr<storage, i32, read_write>'");
|
"'ptr<storage, i32, read_write>'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(ResolverTest, Expr_Bitcast_ptr) {
|
||||||
|
auto* vf = Var("vf", ty.f32());
|
||||||
|
auto* bitcast = create<ast::BitcastExpression>(
|
||||||
|
Source{{12, 34}}, ty.pointer<i32>(ast::StorageClass::kFunction),
|
||||||
|
Expr("vf"));
|
||||||
|
auto* ip =
|
||||||
|
Const("ip", ty.pointer<i32>(ast::StorageClass::kFunction), bitcast);
|
||||||
|
WrapInFunction(Decl(vf), Decl(ip));
|
||||||
|
|
||||||
|
EXPECT_FALSE(r()->Resolve());
|
||||||
|
EXPECT_EQ(r()->error(), "12:34 error: cannot cast to a pointer");
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace resolver
|
} // namespace resolver
|
||||||
} // namespace tint
|
} // namespace tint
|
||||||
|
|
|
@ -1680,6 +1680,10 @@ bool Resolver::Bitcast(ast::BitcastExpression* expr) {
|
||||||
if (!ty) {
|
if (!ty) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (ty->Is<sem::Pointer>()) {
|
||||||
|
diagnostics_.add_error("cannot cast to a pointer", expr->source());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
SetType(expr, ty, expr->type()->FriendlyName(builder_->Symbols()));
|
SetType(expr, ty, expr->type()->FriendlyName(builder_->Symbols()));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1861,6 +1865,10 @@ bool Resolver::Constructor(ast::ConstructorExpression* expr) {
|
||||||
// Now that the argument types have been determined, make sure that they
|
// Now that the argument types have been determined, make sure that they
|
||||||
// obey the constructor type rules laid out in
|
// obey the constructor type rules laid out in
|
||||||
// https://gpuweb.github.io/gpuweb/wgsl.html#type-constructor-expr.
|
// https://gpuweb.github.io/gpuweb/wgsl.html#type-constructor-expr.
|
||||||
|
if (type->Is<sem::Pointer>()) {
|
||||||
|
diagnostics_.add_error("cannot cast to a pointer", expr->source());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (auto* vec_type = type->As<sem::Vector>()) {
|
if (auto* vec_type = type->As<sem::Vector>()) {
|
||||||
return ValidateVectorConstructor(type_ctor, vec_type);
|
return ValidateVectorConstructor(type_ctor, vec_type);
|
||||||
}
|
}
|
||||||
|
|
|
@ -728,6 +728,18 @@ TEST_F(ResolverValidationTest, OffsetAndAlignAndSizeDecoration) {
|
||||||
"decorations");
|
"decorations");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(ResolverTest, Expr_Constructor_Cast_Pointer) {
|
||||||
|
auto* vf = Var("vf", ty.f32());
|
||||||
|
auto* c = create<ast::TypeConstructorExpression>(
|
||||||
|
Source{{12, 34}}, ty.pointer<i32>(ast::StorageClass::kFunction),
|
||||||
|
ExprList(vf));
|
||||||
|
auto* ip = Const("ip", ty.pointer<i32>(ast::StorageClass::kFunction), c);
|
||||||
|
WrapInFunction(Decl(vf), Decl(ip));
|
||||||
|
|
||||||
|
EXPECT_FALSE(r()->Resolve());
|
||||||
|
EXPECT_EQ(r()->error(), "12:34 error: cannot cast to a pointer");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(ResolverValidationTest, Expr_Constructor_Array_ZeroValue_Pass) {
|
TEST_F(ResolverValidationTest, Expr_Constructor_Array_ZeroValue_Pass) {
|
||||||
// array<u32, 10>();
|
// array<u32, 10>();
|
||||||
auto* tc = array<u32, 10>();
|
auto* tc = array<u32, 10>();
|
||||||
|
|
Loading…
Reference in New Issue