tint: Prevent function calls at module-scope
Bug: chromium:1339723 Bug: tint:1606 Change-Id: Ia2e10d6ac38fde0a9c851d279fe07f50f108546e Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/95081 Reviewed-by: Dan Sinclair <dsinclair@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
aa037ac489
commit
c7d6ab6c5a
|
@ -354,10 +354,19 @@ TEST_F(ResolverFunctionValidationTest, CannotCallEntryPoint) {
|
|||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
EXPECT_EQ(r()->error(),
|
||||
|
||||
R"(12:34 error: entry point functions cannot be the target of a function call)");
|
||||
}
|
||||
|
||||
TEST_F(ResolverFunctionValidationTest, CannotCallFunctionAtModuleScope) {
|
||||
// fn F() -> i32 { return 1; }
|
||||
// var x = F();
|
||||
Func("F", {}, ty.i32(), {Return(1_i)});
|
||||
GlobalVar("x", nullptr, Call(Source{{12, 34}}, "F"), ast::StorageClass::kPrivate);
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
EXPECT_EQ(r()->error(), R"(12:34 error: functions cannot be called at module-scope)");
|
||||
}
|
||||
|
||||
TEST_F(ResolverFunctionValidationTest, PipelineStage_MustBeUnique_Fail) {
|
||||
// @fragment
|
||||
// @vertex
|
||||
|
|
|
@ -1695,6 +1695,11 @@ bool Validator::FunctionCall(const sem::Call* call, sem::Statement* current_stat
|
|||
auto sym = decl->target.name->symbol;
|
||||
auto name = symbols_.NameFor(sym);
|
||||
|
||||
if (!current_statement) { // Function call at module-scope.
|
||||
AddError("functions cannot be called at module-scope", decl->source);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (target->Declaration()->IsEntryPoint()) {
|
||||
// https://www.w3.org/TR/WGSL/#function-restriction
|
||||
// An entry point must never be the target of a function call.
|
||||
|
|
Loading…
Reference in New Issue