diff --git a/lld/COFF/Options.td b/lld/COFF/Options.td --- a/lld/COFF/Options.td +++ b/lld/COFF/Options.td @@ -166,7 +166,8 @@ HelpText<"Allow multiply defined symbols when creating executables">; def force_multipleres : F<"force:multipleres">, HelpText<"Allow multiply defined resources when creating executables">; -defm WX : B<"WX", "Treat warnings as errors", "Don't treat warnings as errors">; +defm WX : B<"WX", "Treat warnings as errors", + "Don't treat warnings as errors (default)">; defm allowbind : B<"allowbind", "Enable DLL binding (default)", "Disable DLL binding">; diff --git a/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp b/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp --- a/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp +++ b/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp @@ -229,10 +229,11 @@ (Magic == file_magic::coff_object) ? getCOFFFileMachine(MB) : getBitcodeFileMachine(MB); if (!MaybeFileMachine) { - handleAllErrors(MaybeFileMachine.takeError(), [&](const ErrorInfoBase &EIB) { - llvm::errs() << MB.getBufferIdentifier() << ": " << EIB.message() - << "\n"; - }); + handleAllErrors(MaybeFileMachine.takeError(), + [&](const ErrorInfoBase &EIB) { + llvm::errs() << MB.getBufferIdentifier() << ": " + << EIB.message() << "\n"; + }); exit(1); } COFF::MachineTypes FileMachine = *MaybeFileMachine; @@ -291,10 +292,25 @@ return 0; } + // Parse /ignore: + llvm::StringSet<> IgnoredWarnings; + for (auto *Arg : Args.filtered(OPT_ignore)) + IgnoredWarnings.insert(Arg->getValue()); + // If no input files and not told otherwise, silently do nothing to match // lib.exe - if (!Args.hasArgNoClaim(OPT_INPUT) && !Args.hasArg(OPT_llvmlibempty)) + if (!Args.hasArgNoClaim(OPT_INPUT) && !Args.hasArg(OPT_llvmlibempty)) { + if (!IgnoredWarnings.contains("emptyoutput")) { + llvm::errs() << "warning: no input files, not writing output file\n"; + llvm::errs() << " pass /llvmlibempty to write empty .lib file,\n"; + llvm::errs() << " pass /ignore:emptyoutput to suppress warning\n"; + if (Args.hasFlag(OPT_WX, OPT_WX_no, false)) { + llvm::errs() << "treating warning as error due to /WX\n"; + return 1; + } + } return 0; + } if (Args.hasArg(OPT_lst)) { doList(Args); diff --git a/llvm/lib/ToolDrivers/llvm-lib/Options.td b/llvm/lib/ToolDrivers/llvm-lib/Options.td --- a/llvm/lib/ToolDrivers/llvm-lib/Options.td +++ b/llvm/lib/ToolDrivers/llvm-lib/Options.td @@ -9,6 +9,14 @@ class P : Joined<["/", "-", "/?", "-?"], name#":">, HelpText; +// Boolean flag which can be suffixed by ":no". Using it unsuffixed turns the +// flag on and using it suffixed by ":no" turns it off. +multiclass B { + def "" : F, HelpText; + def _no : F, HelpText; +} + +def ignore : P<"ignore", "Specify warning codes to ignore">; def libpath: P<"libpath", "Object file search path">; // Can't be called "list" since that's a keyword. @@ -23,6 +31,9 @@ def machine: P<"machine", "Specify target platform">; +defm WX : B<"WX", "Treat warnings as errors", + "Don't treat warnings as errors (default)">; + def help : F<"help">; // /?? and -?? must be before /? and -? to not confuse lib/Options. @@ -32,7 +43,4 @@ // The flags below do nothing. They are defined only for lib.exe compatibility. //============================================================================== -class QF : Joined<["/", "-", "/?", "-?"], name#":">; - -def ignore : QF<"ignore">; def nologo : F<"nologo">; diff --git a/llvm/test/tools/llvm-lib/no-inputs.test b/llvm/test/tools/llvm-lib/no-inputs.test --- a/llvm/test/tools/llvm-lib/no-inputs.test +++ b/llvm/test/tools/llvm-lib/no-inputs.test @@ -1,7 +1,22 @@ RUN: rm -f %t.lib -RUN: llvm-lib -out:%t.lib +RUN: llvm-lib -out:%t.lib 2>&1 | FileCheck --check-prefix=EMPTYWARN %s RUN: test ! -e %t.lib +RUN: not llvm-lib -out:%t.lib /WX 2>&1 | FileCheck --check-prefix=EMPTYWARN %s +RUN: test ! -e %t.lib +RUN: llvm-lib -out:%t.lib /WX /WX:no 2>&1 \ +RUN: | FileCheck --check-prefix=EMPTYWARN %s +RUN: test ! -e %t.lib +RUN: llvm-lib /ignore:emptyoutput -out:%t.lib 2>&1 \ +RUN: | FileCheck --check-prefix=NOEMPTYWARN --allow-empty %s +RUN: test ! -e %t.lib +RUN: llvm-lib /ignore:emptyoutput /WX -out:%t.lib 2>&1 \ +RUN: | FileCheck --check-prefix=NOEMPTYWARN --allow-empty %s +RUN: test ! -e %t.lib + +EMPTYWARN: warning: no input files, not writing output file +NOEMPTYWARN-NOT: warning: no input files, not writing output file -RUN: llvm-lib /llvmlibempty -out:%t.lib +RUN: llvm-lib /llvmlibempty -out:%t.lib 2>&1 \ +RUN: | FileCheck --check-prefix=NOEMPTYWARN --allow-empty %s RUN: FileCheck %s < %t.lib CHECK: !