Index: lld/trunk/COFF/Config.h =================================================================== --- lld/trunk/COFF/Config.h +++ lld/trunk/COFF/Config.h @@ -90,6 +90,7 @@ uint64_t ErrorLimit = 20; bool Relocatable = true; bool Force = false; + bool FatalWarnings = false; bool Debug = false; bool WriteSymtab = true; unsigned DebugTypes = static_cast(DebugType::None); Index: lld/trunk/COFF/DriverUtils.cpp =================================================================== --- lld/trunk/COFF/DriverUtils.cpp +++ lld/trunk/COFF/DriverUtils.cpp @@ -738,6 +738,9 @@ message(Msg); } + // Handle /WX early since it converts missing argument warnings to errors. + Config->FatalWarnings = Args.hasFlag(OPT_WX, OPT_WX_no, false); + if (MissingCount) fatal(Twine(Args.getArgString(MissingIndex)) + ": missing argument"); for (auto *Arg : Args.filtered(OPT_UNKNOWN)) Index: lld/trunk/COFF/Error.cpp =================================================================== --- lld/trunk/COFF/Error.cpp +++ lld/trunk/COFF/Error.cpp @@ -106,6 +106,11 @@ } void warn(const Twine &Msg) { + if (Config->FatalWarnings) { + error(Msg); + return; + } + std::lock_guard Lock(Mu); print("warning: ", raw_ostream::MAGENTA); *ErrorOS << Msg << "\n"; Index: lld/trunk/COFF/Options.td =================================================================== --- lld/trunk/COFF/Options.td +++ lld/trunk/COFF/Options.td @@ -85,6 +85,7 @@ def force : F<"force">, HelpText<"Allow undefined symbols when creating executables">; def force_unresolved : F<"force:unresolved">; +defm WX : B<"WX", "Treat warnings as errors", "Don't treat warnings as errors">; defm allowbind : B<"allowbind", "Enable DLL binding (default)", "Disable DLL binding">; @@ -162,5 +163,3 @@ def tlbout : QF<"tlbout">; def verbose_all : QF<"verbose">; def guardsym : QF<"guardsym">; - -defm wx : QB<"wx">; Index: lld/trunk/test/COFF/wx.s =================================================================== --- lld/trunk/test/COFF/wx.s +++ lld/trunk/test/COFF/wx.s @@ -0,0 +1,17 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -triple=x86_64-windows-msvc -filetype=obj -o %t.obj %s +# RUN: not lld-link /out:%t.exe /entry:main -notarealoption /WX %t.obj 2>&1 | \ +# RUN: FileCheck -check-prefix=ERROR %s +# RUN: not lld-link /out:%t.exe /entry:main -notarealoption /WX:NO /WX %t.obj 2>&1 | \ +# RUN: FileCheck -check-prefix=ERROR %s +# RUN: lld-link /out:%t.exe /entry:main -notarealoption /WX /WX:NO %t.obj 2>&1 | \ +# RUN: FileCheck -check-prefix=WARNING %s + +# ERROR: error: ignoring unknown argument: -notarealoption +# WARNING: warning: ignoring unknown argument: -notarealoption + +.text +.global main +main: + ret