From 7a0daa233d8a40583f5c0055f5a9d41b802669c5 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Wed, 9 Dec 2020 15:15:20 +0000 Subject: [PATCH] transform: Fix Manager::Run() with no transforms If there are transforms added to the manager, then Run() would output an empty module. Fix this. Bug: tint:390 Bug: tint:389 Change-Id: I439fe7a28816761f3702e304ef130b7a6992ecce Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35280 Reviewed-by: dan sinclair Commit-Queue: Ben Clayton --- src/transform/manager.cc | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/transform/manager.cc b/src/transform/manager.cc index cbb6ffec34..7ba0fb71b6 100644 --- a/src/transform/manager.cc +++ b/src/transform/manager.cc @@ -24,17 +24,21 @@ Manager::~Manager() = default; Transform::Output Manager::Run(ast::Module* module) { Output out; - for (auto& transform : transforms_) { - auto res = transform->Run(module); - out.module = std::move(res.module); - out.diagnostics.add(std::move(res.diagnostics)); - if (out.diagnostics.contains_errors()) { - return out; + if (!transforms_.empty()) { + for (auto& transform : transforms_) { + auto res = transform->Run(module); + out.module = std::move(res.module); + out.diagnostics.add(std::move(res.diagnostics)); + if (out.diagnostics.contains_errors()) { + return out; + } + module = &out.module; } - module = &out.module; + } else { + out.module = module->Clone(); } - TypeDeterminer td(module); + TypeDeterminer td(&out.module); if (!td.Determine()) { diag::Diagnostic err; err.severity = diag::Severity::Error;