tint/transform: Strip unused atomic builtins
If a SPIR-V program declared spirv-atomic stubs, but didn't call them then the transform could be skipped, leaving stub functions behind. This could cause writers to vomit. Ensure that these are correctly stripped. Bug: oss-fuzz:54057 Change-Id: I27c89a621163b1a3cc5e2ef375f846a094434062 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/113023 Commit-Queue: Ben Clayton <bclayton@google.com> Auto-Submit: Ben Clayton <bclayton@google.com> Reviewed-by: James Price <jrprice@google.com> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
parent
d3137f0ac3
commit
c07de73b0b
|
@ -64,6 +64,8 @@ struct SpirvAtomic::State {
|
||||||
/// Runs the transform
|
/// Runs the transform
|
||||||
/// @returns the new program or SkipTransform if the transform is not required
|
/// @returns the new program or SkipTransform if the transform is not required
|
||||||
ApplyResult Run() {
|
ApplyResult Run() {
|
||||||
|
bool made_changes = false;
|
||||||
|
|
||||||
// Look for stub functions generated by the SPIR-V reader, which are used as placeholders
|
// Look for stub functions generated by the SPIR-V reader, which are used as placeholders
|
||||||
// for atomic builtin calls.
|
// for atomic builtin calls.
|
||||||
for (auto* fn : ctx.src->AST().Functions()) {
|
for (auto* fn : ctx.src->AST().Functions()) {
|
||||||
|
@ -104,10 +106,11 @@ struct SpirvAtomic::State {
|
||||||
|
|
||||||
// Remove the stub from the output program
|
// Remove the stub from the output program
|
||||||
ctx.Remove(ctx.src->AST().GlobalDeclarations(), fn);
|
ctx.Remove(ctx.src->AST().GlobalDeclarations(), fn);
|
||||||
|
made_changes = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (atomic_expressions.IsEmpty()) {
|
if (!made_changes) {
|
||||||
return SkipTransform;
|
return SkipTransform;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -151,6 +151,19 @@ class SpirvAtomicTest : public TransformTest {
|
||||||
std::vector<std::unique_ptr<Source::File>> files_;
|
std::vector<std::unique_ptr<Source::File>> files_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
TEST_F(SpirvAtomicTest, StripUnusedBuiltins) {
|
||||||
|
auto* src = R"(
|
||||||
|
fn f() {
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
|
||||||
|
auto* expect = src;
|
||||||
|
|
||||||
|
auto got = Run(src);
|
||||||
|
|
||||||
|
EXPECT_EQ(expect, str(got));
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(SpirvAtomicTest, ArrayOfU32) {
|
TEST_F(SpirvAtomicTest, ArrayOfU32) {
|
||||||
auto* src = R"(
|
auto* src = R"(
|
||||||
var<workgroup> wg : array<u32, 4>;
|
var<workgroup> wg : array<u32, 4>;
|
||||||
|
|
Loading…
Reference in New Issue