Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -1950,6 +1950,8 @@ HelpText<"Force linking the clang builtins runtime library">; def flto_EQ : Joined<["-"], "flto=">, Flags<[CoreOption, CC1Option]>, Group, HelpText<"Set LTO mode to either 'full' or 'thin'">, Values<"thin,full">; +def flto_EQ_jobserver : Flag<["-"], "flto=jobserver">, Group; +def flto_EQ_auto : Flag<["-"], "flto=auto">, Group; def flto : Flag<["-"], "flto">, Flags<[CoreOption, CC1Option]>, Group, HelpText<"Enable LTO in 'full' mode">; def fno_lto : Flag<["-"], "fno-lto">, Flags<[CoreOption, CC1Option]>, Group, @@ -4244,8 +4246,6 @@ defm branch_count_reg : BooleanFFlag<"branch-count-reg">, Group; defm default_inline : BooleanFFlag<"default-inline">, Group; defm fat_lto_objects : BooleanFFlag<"fat-lto-objects">, Group; -def : Flag<["-"], "flto=auto">, Group; -def : Flag<["-"], "flto=jobserver">, Group; defm float_store : BooleanFFlag<"float-store">, Group; defm friend_injection : BooleanFFlag<"friend-injection">, Group; defm function_attribute_list : BooleanFFlag<"function-attribute-list">, Group; Index: clang/lib/Driver/Driver.cpp =================================================================== --- clang/lib/Driver/Driver.cpp +++ clang/lib/Driver/Driver.cpp @@ -598,7 +598,9 @@ void Driver::setLTOMode(const llvm::opt::ArgList &Args) { LTOMode = LTOK_None; if (!Args.hasFlag(options::OPT_flto, options::OPT_flto_EQ, - options::OPT_fno_lto, false)) + options::OPT_fno_lto, false) && + !Args.hasArg(options::OPT_flto_EQ_auto) && + !Args.hasArg(options::OPT_flto_EQ_jobserver)) return; StringRef LTOName("full"); Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -4454,7 +4454,14 @@ JA.isDeviceOffloading(Action::OFK_Host)); if (D.isUsingLTO() && !isDeviceOffloadAction) { - Args.AddLastArg(CmdArgs, options::OPT_flto, options::OPT_flto_EQ); + if (Args.hasArg(options::OPT_flto)) + CmdArgs.push_back("-flto"); + else { + if (D.getLTOMode() == LTOK_Thin) + CmdArgs.push_back("-flto=thin"); + else + CmdArgs.push_back("-flto=full"); + } CmdArgs.push_back("-flto-unit"); } } Index: clang/test/Driver/lto.c =================================================================== --- clang/test/Driver/lto.c +++ clang/test/Driver/lto.c @@ -77,3 +77,11 @@ // // CHECK-TUNING-LLDB: "-plugin-opt=-debugger-tune=lldb" // CHECK-NO-TUNING-NOT: "-plugin-opt=-debugger-tune +// +// -flto=auto and -flto=jobserver pass along -flto=full +// RUN: %clang -target x86_64-unknown-linux -### %s -flto=auto 2>&1 | FileCheck --check-prefix=FLTO-AUTO %s +// RUN: %clang -target x86_64-unknown-linux -### %s -flto=jobserver 2>&1 | FileCheck --check-prefix=FLTO-JOBSERVER %s +// +// FLTO-AUTO: -flto=full +// FLTO-JOBSERVER: -flto=full +//