[PATCH] D39148: [COFF] Add support for /WX

Shoaib Meenai via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 20 15:47:10 PDT 2017


smeenai created this revision.

link.exe supports this option to convert warnings into errors, and it's
useful to support in LLD as well.


https://reviews.llvm.org/D39148

Files:
  COFF/Config.h
  COFF/DriverUtils.cpp
  COFF/Error.cpp
  COFF/Options.td
  test/COFF/wx.s


Index: test/COFF/wx.s
===================================================================
--- /dev/null
+++ 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
Index: COFF/Options.td
===================================================================
--- COFF/Options.td
+++ COFF/Options.td
@@ -84,6 +84,8 @@
 def force : F<"force">,
     HelpText<"Allow undefined symbols when creating executables">;
 def force_unresolved : F<"force:unresolved">;
+def WX : F<"WX">, HelpText<"Treat warnings as errors">;
+def WX_no : F<"WX:no">, HelpText<"Don't treat warnings as errors">;
 
 defm allowbind: B<"allowbind", "Disable DLL binding">;
 defm allowisolation : B<"allowisolation", "Set NO_ISOLATION bit">;
@@ -146,5 +148,3 @@
 def tlbout : QF<"tlbout">;
 def verbose_all : QF<"verbose">;
 def guardsym : QF<"guardsym">;
-
-defm wx : QB<"wx">;
Index: COFF/Error.cpp
===================================================================
--- COFF/Error.cpp
+++ COFF/Error.cpp
@@ -105,6 +105,11 @@
 }
 
 void warn(const Twine &Msg) {
+  if (Config->FatalWarnings) {
+    error(Msg);
+    return;
+  }
+
   std::lock_guard<std::mutex> Lock(Mu);
   print("warning: ", raw_ostream::MAGENTA);
   *ErrorOS << Msg << "\n";
Index: COFF/DriverUtils.cpp
===================================================================
--- COFF/DriverUtils.cpp
+++ COFF/DriverUtils.cpp
@@ -738,6 +738,10 @@
     message(Msg);
   }
 
+  // Handle /WX early since it converts missing argument warnings to errors.
+  if (auto *Arg = Args.getLastArg(OPT_WX, OPT_WX_no))
+    Config->FatalWarnings = Arg->getOption().getID() == OPT_WX;
+
   if (MissingCount)
     fatal(Twine(Args.getArgString(MissingIndex)) + ": missing argument");
   for (auto *Arg : Args.filtered(OPT_UNKNOWN))
Index: COFF/Config.h
===================================================================
--- COFF/Config.h
+++ 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<unsigned>(DebugType::None);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39148.119721.patch
Type: text/x-patch
Size: 2729 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171020/81a3e6ec/attachment.bin>


More information about the llvm-commits mailing list