Validate attributes on function parameters

Entry point function parameter can only have builtin and location
attributes (unless a disable validation attribute is present). Other
functions cannot have any decorations on their parameters.

Fix parameter creation in the CanonicalizeEntryPointIO transform for a
case where it was not stripping attributes that are not valid for
function parameters.

Change-Id: I000908aa2dc007c52d100c5f65bca051a49bec9a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/55863
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
James Price
2021-06-24 16:20:16 +00:00
committed by Tint LUCI CQ
parent 14c0b8acbf
commit c3f19081f8
4 changed files with 126 additions and 28 deletions

View File

@@ -151,6 +151,13 @@ Output CanonicalizeEntryPointIO::Run(const Program* in, const DataMap& data) {
<< "nested pipeline IO struct";
}
ast::DecorationList new_decorations = RemoveDecorations(
&ctx, member->Declaration()->decorations(),
[](const ast::Decoration* deco) {
return !deco->IsAnyOf<ast::BuiltinDecoration,
ast::LocationDecoration>();
});
if (cfg->builtin_style == BuiltinStyle::kParameter &&
ast::HasDecoration<ast::BuiltinDecoration>(
member->Declaration()->decorations())) {
@@ -158,19 +165,12 @@ Output CanonicalizeEntryPointIO::Run(const Program* in, const DataMap& data) {
// parameters, then move it to the parameter list.
auto* member_ty = CreateASTTypeFor(&ctx, member->Type());
auto new_param_name = ctx.dst->Sym();
new_parameters.push_back(ctx.dst->Param(
new_param_name, member_ty,
ctx.Clone(member->Declaration()->decorations())));
new_parameters.push_back(
ctx.dst->Param(new_param_name, member_ty, new_decorations));
init_values.push_back(ctx.dst->Expr(new_param_name));
continue;
}
ast::DecorationList new_decorations = RemoveDecorations(
&ctx, member->Declaration()->decorations(),
[](const ast::Decoration* deco) {
return !deco->IsAnyOf<ast::BuiltinDecoration,
ast::LocationDecoration>();
});
auto member_name = ctx.Clone(member->Declaration()->symbol());
auto* member_type = ctx.Clone(member->Declaration()->type());
new_struct_members.push_back(