tint/resolver: Fix calling of builtins at module-scope

No builtins are implemented as `@const` yet, but validation handles this already.

Bug: chromium:1341472
Change-Id: Id85893345299ba3414e2d15b85dd071c326f481d
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/95762
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton 2022-07-07 17:04:21 +00:00 committed by Dawn LUCI CQ
parent 89bdea0f77
commit b6c8ea9624
2 changed files with 14 additions and 3 deletions

View File

@ -1577,6 +1577,16 @@ TEST_F(ResolverBuiltinTest, Determinant_NotMatrix) {
)");
}
TEST_F(ResolverBuiltinTest, ModuleScopeUsage) {
GlobalConst("c", ty.f32(), Call(Source{{12, 34}}, "abs", 1._f));
EXPECT_FALSE(r()->Resolve());
// TODO(crbug.com/tint/1581): Once 'abs' is implemented as @const, this will no longer be an
// error.
EXPECT_EQ(r()->error(), R"(12:34 error: 'const' initializer must be constant expression)");
}
using ResolverBuiltinTest_Texture = ResolverTestWithParam<ast::builtin::test::TextureOverloadCase>;
INSTANTIATE_TEST_SUITE_P(ResolverTest,

View File

@ -1706,7 +1706,10 @@ sem::Call* Resolver::BuiltinCall(const ast::CallExpression* expr,
auto* call = builder_->create<sem::Call>(expr, builtin.sem, std::move(args), current_statement_,
constant, has_side_effects);
if (current_function_) {
current_function_->AddDirectlyCalledBuiltin(builtin.sem);
current_function_->AddDirectCall(call);
}
if (!validator_.RequiredExtensionForBuiltinFunction(call, enabled_extensions_)) {
return nullptr;
@ -1723,8 +1726,6 @@ sem::Call* Resolver::BuiltinCall(const ast::CallExpression* expr,
return nullptr;
}
current_function_->AddDirectCall(call);
return call;
}