Cloning: move arguments to create() into temporary locals

In C++ argument evaluation order is undefined. MSVC and Clang evaluate these in different orders, leading to hilarity when writing tests that expect a deterministic ordering.

Pull out all the argument expressions to create() in the clone functions so a cloned program is deterministic in its ordering between compilers.

Change-Id: I8e2de31398960c480ce7ee1dfaac4f67652d2dbc
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41544
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Auto-Submit: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton
2021-02-11 20:27:14 +00:00
committed by Commit Bot service account
parent 7b6bcb6e0b
commit 545c9742d5
56 changed files with 237 additions and 108 deletions

View File

@@ -77,7 +77,9 @@ uint64_t AccessControl::BaseAlignment(MemoryLayout mem_layout) const {
}
AccessControl* AccessControl::Clone(CloneContext* ctx) const {
return ctx->dst->create<AccessControl>(access_, ctx->Clone(subtype_));
// Clone arguments outside of create() call to have deterministic ordering
auto* ty = ctx->Clone(type());
return ctx->dst->create<AccessControl>(access_, ty);
}
} // namespace type

View File

@@ -50,7 +50,10 @@ uint64_t Alias::BaseAlignment(MemoryLayout mem_layout) const {
}
Alias* Alias::Clone(CloneContext* ctx) const {
return ctx->dst->create<Alias>(ctx->Clone(symbol()), ctx->Clone(subtype_));
// Clone arguments outside of create() call to have deterministic ordering
auto sym = ctx->Clone(symbol());
auto* ty = ctx->Clone(type());
return ctx->dst->create<Alias>(sym, ty);
}
} // namespace type

View File

@@ -109,8 +109,10 @@ std::string Array::FriendlyName(const SymbolTable& symbols) const {
}
Array* Array::Clone(CloneContext* ctx) const {
return ctx->dst->create<Array>(ctx->Clone(subtype_), size_,
ctx->Clone(decorations()));
// Clone arguments outside of create() call to have deterministic ordering
auto* ty = ctx->Clone(type());
auto decos = ctx->Clone(decorations());
return ctx->dst->create<Array>(ty, size_, decos);
}
} // namespace type

View File

@@ -63,7 +63,9 @@ uint64_t Matrix::BaseAlignment(MemoryLayout mem_layout) const {
}
Matrix* Matrix::Clone(CloneContext* ctx) const {
return ctx->dst->create<Matrix>(ctx->Clone(subtype_), rows_, columns_);
// Clone arguments outside of create() call to have deterministic ordering
auto* ty = ctx->Clone(type());
return ctx->dst->create<Matrix>(ty, rows_, columns_);
}
} // namespace type

View File

@@ -49,7 +49,9 @@ std::string MultisampledTexture::FriendlyName(
}
MultisampledTexture* MultisampledTexture::Clone(CloneContext* ctx) const {
return ctx->dst->create<MultisampledTexture>(dim(), ctx->Clone(type_));
// Clone arguments outside of create() call to have deterministic ordering
auto* ty = ctx->Clone(type());
return ctx->dst->create<MultisampledTexture>(dim(), ty);
}
} // namespace type

View File

@@ -46,7 +46,9 @@ Pointer::Pointer(Pointer&&) = default;
Pointer::~Pointer() = default;
Pointer* Pointer::Clone(CloneContext* ctx) const {
return ctx->dst->create<Pointer>(ctx->Clone(subtype_), storage_class_);
// Clone arguments outside of create() call to have deterministic ordering
auto* ty = ctx->Clone(type());
return ctx->dst->create<Pointer>(ty, storage_class_);
}
} // namespace type

View File

@@ -47,7 +47,9 @@ std::string SampledTexture::FriendlyName(const SymbolTable& symbols) const {
}
SampledTexture* SampledTexture::Clone(CloneContext* ctx) const {
return ctx->dst->create<SampledTexture>(dim(), ctx->Clone(type_));
// Clone arguments outside of create() call to have deterministic ordering
auto* ty = ctx->Clone(type());
return ctx->dst->create<SampledTexture>(dim(), ty);
}
} // namespace type

View File

@@ -163,8 +163,9 @@ std::string StorageTexture::FriendlyName(const SymbolTable&) const {
}
StorageTexture* StorageTexture::Clone(CloneContext* ctx) const {
return ctx->dst->create<StorageTexture>(dim(), image_format_,
ctx->Clone(subtype_));
// Clone arguments outside of create() call to have deterministic ordering
auto* ty = ctx->Clone(type());
return ctx->dst->create<StorageTexture>(dim(), image_format_, ty);
}
type::Type* StorageTexture::SubtypeFor(type::ImageFormat format,

View File

@@ -87,7 +87,10 @@ uint64_t Struct::BaseAlignment(MemoryLayout mem_layout) const {
}
Struct* Struct::Clone(CloneContext* ctx) const {
return ctx->dst->create<Struct>(ctx->Clone(symbol()), ctx->Clone(struct_));
// Clone arguments outside of create() call to have deterministic ordering
auto sym = ctx->Clone(symbol());
auto* str = ctx->Clone(impl());
return ctx->dst->create<Struct>(sym, str);
}
} // namespace type

View File

@@ -59,7 +59,9 @@ uint64_t Vector::BaseAlignment(MemoryLayout mem_layout) const {
}
Vector* Vector::Clone(CloneContext* ctx) const {
return ctx->dst->create<Vector>(ctx->Clone(subtype_), size_);
// Clone arguments outside of create() call to have deterministic ordering
auto* ty = ctx->Clone(type());
return ctx->dst->create<Vector>(ty, size_);
}
} // namespace type