From b6c8ea9624b8bd0a7e75290206501d1235ef74c5 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Thu, 7 Jul 2022 17:04:21 +0000 Subject: [PATCH] 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 Commit-Queue: Ben Clayton --- src/tint/resolver/builtin_test.cc | 10 ++++++++++ src/tint/resolver/resolver.cc | 7 ++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/tint/resolver/builtin_test.cc b/src/tint/resolver/builtin_test.cc index 38f562010d..fa773b3446 100644 --- a/src/tint/resolver/builtin_test.cc +++ b/src/tint/resolver/builtin_test.cc @@ -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; INSTANTIATE_TEST_SUITE_P(ResolverTest, diff --git a/src/tint/resolver/resolver.cc b/src/tint/resolver/resolver.cc index 81ff6ee34c..4f47096d60 100644 --- a/src/tint/resolver/resolver.cc +++ b/src/tint/resolver/resolver.cc @@ -1706,7 +1706,10 @@ sem::Call* Resolver::BuiltinCall(const ast::CallExpression* expr, auto* call = builder_->create(expr, builtin.sem, std::move(args), current_statement_, constant, has_side_effects); - current_function_->AddDirectlyCalledBuiltin(builtin.sem); + 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; }