IntrinsicTable: remove double underscores

'__' is reserved in C++, and the 'match__' and 'build__' functions are causing OSS-fuzz builds to fail.

Add the change in tint behavior to the OT notes.

Add end to end tests for underscores. While the GLSL and MSL compilers seem to accept leading and double underscores in identifiers, the tint build failure has highlighted we have more work to do here (crbug.com/tint/1319)

Fixed: oss-fuzz:41214
Bug: tint:1292
Bug: tint:1319
Change-Id: I32b7bf4e0cff26e678b788457f90452c2503da50
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/70480
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
Ben Clayton
2021-11-22 15:24:16 +00:00
committed by Tint LUCI CQ
parent 4183051b54
commit 177e7bfa5d
95 changed files with 1279 additions and 19 deletions

View File

@@ -657,20 +657,20 @@ const sem::ExternalTexture* build_texture_external(MatchState& state) {
// Builtin types starting with a _ prefix cannot be declared in WGSL, so they
// can only be used as return types. Because of this, they must only match Any,
// which is used as the return type matcher.
bool match__modf_result(const sem::Type* ty) {
bool match_modf_result(const sem::Type* ty) {
return ty->Is<Any>();
}
bool match__modf_result_vec(const sem::Type* ty, Number& N) {
bool match_modf_result_vec(const sem::Type* ty, Number& N) {
if (!ty->Is<Any>()) {
return false;
}
N = Number::any;
return true;
}
bool match__frexp_result(const sem::Type* ty) {
bool match_frexp_result(const sem::Type* ty) {
return ty->Is<Any>();
}
bool match__frexp_result_vec(const sem::Type* ty, Number& N) {
bool match_frexp_result_vec(const sem::Type* ty, Number& N) {
if (!ty->Is<Any>()) {
return false;
}
@@ -715,22 +715,22 @@ const sem::Struct* build_struct(
/* size_no_padding */ size_without_padding);
}
const sem::Struct* build__modf_result(MatchState& state) {
const sem::Struct* build_modf_result(MatchState& state) {
auto* f32 = state.builder.create<sem::F32>();
return build_struct(state, "__modf_result", {{"fract", f32}, {"whole", f32}});
}
const sem::Struct* build__modf_result_vec(MatchState& state, Number& n) {
const sem::Struct* build_modf_result_vec(MatchState& state, Number& n) {
auto* vec_f32 = state.builder.create<sem::Vector>(
state.builder.create<sem::F32>(), n.Value());
return build_struct(state, "__modf_result_vec" + std::to_string(n.Value()),
{{"fract", vec_f32}, {"whole", vec_f32}});
}
const sem::Struct* build__frexp_result(MatchState& state) {
const sem::Struct* build_frexp_result(MatchState& state) {
auto* f32 = state.builder.create<sem::F32>();
auto* i32 = state.builder.create<sem::I32>();
return build_struct(state, "__frexp_result", {{"sig", f32}, {"exp", i32}});
}
const sem::Struct* build__frexp_result_vec(MatchState& state, Number& n) {
const sem::Struct* build_frexp_result_vec(MatchState& state, Number& n) {
auto* vec_f32 = state.builder.create<sem::Vector>(
state.builder.create<sem::F32>(), n.Value());
auto* vec_i32 = state.builder.create<sem::Vector>(

View File

@@ -1050,10 +1050,10 @@ class ModfResult : public TypeMatcher {
};
const sem::Type* ModfResult::Match(MatchState& state, const sem::Type* ty) const {
if (!match__modf_result(ty)) {
if (!match_modf_result(ty)) {
return nullptr;
}
return build__modf_result(state);
return build_modf_result(state);
}
std::string ModfResult::String(MatchState&) const {
@@ -1078,14 +1078,14 @@ class ModfResultVec : public TypeMatcher {
const sem::Type* ModfResultVec::Match(MatchState& state, const sem::Type* ty) const {
Number N = Number::invalid;
if (!match__modf_result_vec(ty, N)) {
if (!match_modf_result_vec(ty, N)) {
return nullptr;
}
N = state.Num(N);
if (!N.IsValid()) {
return nullptr;
}
return build__modf_result_vec(state, N);
return build_modf_result_vec(state, N);
}
std::string ModfResultVec::String(MatchState& state) const {
@@ -1112,10 +1112,10 @@ class FrexpResult : public TypeMatcher {
};
const sem::Type* FrexpResult::Match(MatchState& state, const sem::Type* ty) const {
if (!match__frexp_result(ty)) {
if (!match_frexp_result(ty)) {
return nullptr;
}
return build__frexp_result(state);
return build_frexp_result(state);
}
std::string FrexpResult::String(MatchState&) const {
@@ -1140,14 +1140,14 @@ class FrexpResultVec : public TypeMatcher {
const sem::Type* FrexpResultVec::Match(MatchState& state, const sem::Type* ty) const {
Number N = Number::invalid;
if (!match__frexp_result_vec(ty, N)) {
if (!match_frexp_result_vec(ty, N)) {
return nullptr;
}
N = state.Num(N);
if (!N.IsValid()) {
return nullptr;
}
return build__frexp_result_vec(state, N);
return build_frexp_result_vec(state, N);
}
std::string FrexpResultVec::String(MatchState& state) const {

View File

@@ -148,7 +148,7 @@ const sem::Type* {{$class}}::Match(MatchState& state, const sem::Type* ty) const
{{- range .TemplateParams }}
{{- template "DeclareLocalTemplateParam" . }}
{{- end }}
if (!match_{{TrimPrefix .Name "_"}}(ty{{range .TemplateParams}}, {{.GetName}}{{end}})) {
if (!match_{{TrimLeft .Name "_"}}(ty{{range .TemplateParams}}, {{.GetName}}{{end}})) {
return nullptr;
}
{{- range .TemplateParams }}
@@ -157,7 +157,7 @@ const sem::Type* {{$class}}::Match(MatchState& state, const sem::Type* ty) const
return nullptr;
}
{{- end }}
return build_{{TrimPrefix .Name "_"}}(state{{range .TemplateParams}}, {{.GetName}}{{end}});
return build_{{TrimLeft .Name "_"}}(state{{range .TemplateParams}}, {{.GetName}}{{end}});
}
std::string {{$class}}::String(MatchState&{{if .TemplateParams}} state{{end}}) const {