diff --git a/llvm/test/LTO/Resolution/X86/unified-lto-check.ll b/llvm/test/LTO/Resolution/X86/unified-lto-check.ll index cf1e5693165e3..3d751ab205244 100644 --- a/llvm/test/LTO/Resolution/X86/unified-lto-check.ll +++ b/llvm/test/LTO/Resolution/X86/unified-lto-check.ll @@ -38,6 +38,17 @@ ; RUN: llvm-lto2 run --debug-only=lto -o %t3 %t1 %t2 2>&1 | \ ; RUN: FileCheck --allow-empty %s --check-prefix THIN +; Test invalid unified-lto mode causes an error message return. +; RUN: not llvm-lto2 run --unified-lto=foo -o %t3 %t1 %t2 2>&1 | \ +; RUN: FileCheck %s --check-prefix INVALIDMODE +; RUN: not llvm-lto2 run --unified-lto="foo" -o %t3 %t1 %t2 2>&1 | \ +; RUN: FileCheck %s --check-prefix INVALIDMODE +; RUN: not llvm-lto2 run --unified-lto=1 -o %t3 %t1 %t2 2>&1 | \ +; RUN: FileCheck %s --check-prefix INVALIDMODE + +; INVALIDMODE: for the --unified-lto option: Cannot find option named + + ; UNIFIEDERR: unified LTO compilation must use compatible bitcode modules ; NOUNIFIEDERR-NOT: unified LTO compilation must use compatible bitcode modules @@ -54,3 +65,4 @@ target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" + diff --git a/llvm/tools/llvm-lto2/llvm-lto2.cpp b/llvm/tools/llvm-lto2/llvm-lto2.cpp index fbde66666a596..c8f8ca04286c6 100644 --- a/llvm/tools/llvm-lto2/llvm-lto2.cpp +++ b/llvm/tools/llvm-lto2/llvm-lto2.cpp @@ -198,9 +198,16 @@ static cl::list PassPlugins("load-pass-plugin", cl::desc("Load passes from plugin library")); -static cl::opt UnifiedLTOMode("unified-lto", cl::Optional, - cl::desc("Set LTO mode"), - cl::value_desc("mode")); +static cl::opt UnifiedLTOMode( + "unified-lto", cl::Optional, + cl::desc("Set LTO mode with the following options:"), + cl::values(clEnumValN(LTO::LTOK_UnifiedThin, "thin", + "ThinLTO with Unified LTO enabled"), + clEnumValN(LTO::LTOK_UnifiedRegular, "full", + "Regular LTO with Unified LTO enabled"), + clEnumValN(LTO::LTOK_Default, "default", + "Any LTO mode without Unified LTO")), + cl::value_desc("mode"), cl::init(LTO::LTOK_Default)); static cl::opt EnableFreestanding( "lto-freestanding", @@ -404,18 +411,7 @@ static int run(int argc, char **argv) { HasErrors = true; }; - LTO::LTOKind LTOMode = LTO::LTOK_Default; - - if (UnifiedLTOMode == "full") { - LTOMode = LTO::LTOK_UnifiedRegular; - } else if (UnifiedLTOMode == "thin") { - LTOMode = LTO::LTOK_UnifiedThin; - } else if (UnifiedLTOMode == "default") { - LTOMode = LTO::LTOK_Default; - } else if (!UnifiedLTOMode.empty()) { - llvm::errs() << "invalid LTO mode\n"; - return 1; - } + LTO::LTOKind LTOMode = UnifiedLTOMode; LTO Lto(std::move(Conf), std::move(Backend), 1, LTOMode); @@ -578,7 +574,8 @@ static int dumpSymtab(int argc, char **argv) { } if (TT.isOSBinFormatCOFF() && Sym.isWeak() && Sym.isIndirect()) - outs() << " fallback " << Sym.getCOFFWeakExternalFallback() << '\n'; + outs() << " fallback " << Sym.getCOFFWeakExternalFallback() + << '\n'; if (!Sym.getSectionName().empty()) outs() << " section " << Sym.getSectionName() << "\n";