fix crash when alive-tv is given unknown LLVM passes
MODIFY
llvm_util/llvm_optimizer.cpp
llvm_util/llvm_optimizer.cpp
#include "llvm/Passes/PassBuilder.h"
using namespace llvm;
+using namespace std;
namespace llvm_util {
-void optimize_module(llvm::Module *M, llvm::StringRef optArgs) {
+string optimize_module(llvm::Module *M, llvm::StringRef optArgs) {
llvm::LoopAnalysisManager LAM;
llvm::FunctionAnalysisManager FAM;
llvm::CGSCCAnalysisManager CGAM;
@@ -36,11 +37,11 @@ void optimize_module(llvm::Module *M, llvm::StringRef optArgs) {
} else if (optArgs == "Oz") {
MPM = PB.buildPerModuleDefaultPipeline(OptimizationLevel::Oz);
} else {
- if (auto E = PB.parsePassPipeline(MPM, optArgs)) {
- llvm::errs() << E << "\n";
- }
+ if (auto Err = PB.parsePassPipeline(MPM, optArgs))
+ return toString(std::move(Err));
}
MPM.run(*M, MAM);
+ return {};
}
}

MODIFY
llvm_util/llvm_optimizer.h
llvm_util/llvm_optimizer.h
// Distributed under the MIT license that can be found in the LICENSE file.
#include <llvm/ADT/StringRef.h>
+#include <string>
namespace llvm {
class Module;
}
namespace llvm_util {
-void optimize_module(llvm::Module *M, llvm::StringRef optArgs);
+std::string optimize_module(llvm::Module *M, llvm::StringRef optArgs);
}

MODIFY
tools/alive-tv.cpp
tools/alive-tv.cpp
@@ -318,7 +318,11 @@ convenient way to demonstrate an existing optimizer bug.
goto end;
} else {
M2 = CloneModule(*M1);
- optimize_module(M2.get(), optPass);
+ auto err = optimize_module(M2.get(), optPass);
+ if (!err.empty()) {
+ *out << "Error parsing list of LLVM passes: " << err << '\n';
+ return -1;
+ }
}
} else {
M2 = openInputFile(Context, opt_file2);

fix crash when alive-tv is given unknown LLVM passes