From b7a73558e64362e2750bbb66421d90f553d0dc6e Mon Sep 17 00:00:00 2001 From: Whitney Tsang <54643204+whitneywhtsang@users.noreply.github.com> Date: Thu, 11 Aug 2022 18:28:41 -0400 Subject: [PATCH] Fix incorrect behaviour (#22) ### Reported issue: Passing `-debug-only=` doesn't work correctly, causes printout of MLIR lowering steps. ### Issue identified: `-debug-only=` uses an internal object called `CurrentDebugType` to store all the debug string, e.g., given `-debug-only=foo`, then `foo` is stored in `CurrentDebugType`. If `CurrentDebugType` is empty, then it behaves like `-debug`. `InitLLVM` calls llvm_shutdown() on destruction, which cleans up ManagedStatic objects, including `CurrentDebugType`. `InitLLVM` should be created at the scope of `main`. ### Propose solution: Remove the internal scope. Signed-off-by: Tsang, Whitney --- polygeist/tools/cgeist/driver.cc | 46 +++++++++++++++----------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/polygeist/tools/cgeist/driver.cc b/polygeist/tools/cgeist/driver.cc index 151a48f86cd11..a900fa116cc56 100644 --- a/polygeist/tools/cgeist/driver.cc +++ b/polygeist/tools/cgeist/driver.cc @@ -664,31 +664,29 @@ int main(int argc, char **argv) { std::vector files; std::vector commands; - { - cl::list inputFileName(cl::Positional, cl::OneOrMore, - cl::desc(""), - cl::cat(toolOptions)); - - cl::list inputCommandArgs( - "args", cl::Positional, cl::desc(""), cl::ZeroOrMore, - cl::PositionalEatsArgs); - - int size = MLIRArgs.size(); - const char **data = MLIRArgs.data(); - InitLLVM y(size, data); - cl::ParseCommandLineOptions(size, data); - assert(inputFileName.size()); - for (auto inp : inputFileName) { - std::ifstream inputFile(inp); - if (!inputFile.good()) { - outs() << "Not able to open file: " << inp << "\n"; - return -1; - } - files.push_back(inp); - } - for (auto &cmd : inputCommandArgs) { - commands.push_back(cmd); + cl::list inputFileName(cl::Positional, cl::OneOrMore, + cl::desc(""), + cl::cat(toolOptions)); + + cl::list inputCommandArgs( + "args", cl::Positional, cl::desc(""), cl::ZeroOrMore, + cl::PositionalEatsArgs); + + int size = MLIRArgs.size(); + const char **data = MLIRArgs.data(); + InitLLVM y(size, data); + cl::ParseCommandLineOptions(size, data); + assert(inputFileName.size()); + for (auto inp : inputFileName) { + std::ifstream inputFile(inp); + if (!inputFile.good()) { + outs() << "Not able to open file: " << inp << "\n"; + return -1; } + files.push_back(inp); + } + for (auto &cmd : inputCommandArgs) { + commands.push_back(cmd); } // Register and load MLIR Dialects.