From e07c40af14e1752f4afc6388986595a5de017054 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Tue, 22 Mar 2022 14:04:41 +0000 Subject: [PATCH] resolver: Fix ICE when using a builtin as a type Bug: chromium:1308209 Change-Id: I779d7fcb4a32640663077cb2176875f6081098a0 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/84260 Reviewed-by: James Price Kokoro: Kokoro Commit-Queue: Ben Clayton --- src/tint/resolver/resolver.cc | 8 ++++++++ src/tint/resolver/type_validation_test.cc | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/tint/resolver/resolver.cc b/src/tint/resolver/resolver.cc index 5c7e36ae9e..bb05c9d460 100644 --- a/src/tint/resolver/resolver.cc +++ b/src/tint/resolver/resolver.cc @@ -275,6 +275,14 @@ sem::Type* Resolver::Type(const ast::Type* ty) { return nullptr; }, [&](Default) { + if (auto* tn = ty->As()) { + if (IsBuiltin(tn->name)) { + auto name = builder_->Symbols().NameFor(tn->name); + AddError("cannot use builtin '" + name + "' as type", + ty->source); + return nullptr; + } + } TINT_UNREACHABLE(Resolver, diagnostics_) << "Unhandled resolved type '" << (resolved ? resolved->TypeInfo().name : "") diff --git a/src/tint/resolver/type_validation_test.cc b/src/tint/resolver/type_validation_test.cc index 179f064612..64f06589ec 100644 --- a/src/tint/resolver/type_validation_test.cc +++ b/src/tint/resolver/type_validation_test.cc @@ -705,6 +705,14 @@ TEST_F(ResolverTypeValidationTest, FunctionAsType) { note: 'f' declared here)"); } +TEST_F(ResolverTypeValidationTest, BuiltinAsType) { + // var v : max; + Global("v", ty.type_name("max"), ast::StorageClass::kPrivate); + + EXPECT_FALSE(r()->Resolve()); + EXPECT_EQ(r()->error(), "error: cannot use builtin 'max' as type"); +} + namespace GetCanonicalTests { struct Params { builder::ast_type_func_ptr create_ast_type;