Skip to content

Commit eb1905d

Browse files
committed
opt: Don't exit when we can't create a TargetMachine
This more closly matches the previous behaviour that silently ignored the failure. We now print a warning instead of exiting. Fixes: a8f8613
1 parent a8f8613 commit eb1905d

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

llvm/tools/opt/opt.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,6 @@ static bool shouldForceLegacyPM() {
392392
//
393393
int main(int argc, char **argv) {
394394
InitLLVM X(argc, argv);
395-
ExitOnError ExitOnErr(std::string(argv[0]) + ": error: ");
396395

397396
// Enable debug stream buffering.
398397
EnableDebugBuffering = true;
@@ -598,8 +597,15 @@ int main(int argc, char **argv) {
598597
if (ModuleTriple.getArch()) {
599598
CPUStr = codegen::getCPUStr();
600599
FeaturesStr = codegen::getFeaturesStr();
601-
TM = ExitOnErr(codegen::createTargetMachineForTriple(ModuleTriple.str(),
602-
GetCodeGenOptLevel()));
600+
Expected<std::unique_ptr<TargetMachine>> ExpectedTM =
601+
codegen::createTargetMachineForTriple(ModuleTriple.str(),
602+
GetCodeGenOptLevel());
603+
if (auto E = ExpectedTM.takeError()) {
604+
errs() << argv[0] << ": WARNING: failed to create target machine for '"
605+
<< ModuleTriple.str() << "': " << toString(std::move(E)) << "\n";
606+
} else {
607+
TM = std::move(*ExpectedTM);
608+
}
603609
} else if (ModuleTriple.getArchName() != "unknown" &&
604610
ModuleTriple.getArchName() != "") {
605611
errs() << argv[0] << ": unrecognized architecture '"

0 commit comments

Comments
 (0)