From 4bffebb117594d20d7dcab55cecd386bc5412ccb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= <mati865@gmail.com>
Date: Fri, 14 May 2021 19:45:07 +0200
Subject: [LLD][MinGW] Add --fatal-warnings and --no-fatal-warnings
 flags

---
 MinGW/Driver.cpp       | 5 +++++
 MinGW/Options.td       | 3 +++
 test/MinGW/driver.test | 9 +++++++++
 3 files changed, 17 insertions(+)

diff --git a/MinGW/Driver.cpp b/MinGW/Driver.cpp
index f8eb4e76b7f9..e6c6efdd2b95 100644
--- a/MinGW/Driver.cpp
+++ b/MinGW/Driver.cpp
@@ -290,6 +290,11 @@ bool mingw::link(ArrayRef<const char *> argsArr, bool canExitEarly,
     add("-debug:dwarf");
   }
 
+  if (args.hasFlag(OPT_fatal_warnings, OPT_no_fatal_warnings, false))
+    add("-WX");
+  else
+    add("-WX:no");
+
   if (args.hasArg(OPT_shared))
     add("-dll");
   if (args.hasArg(OPT_verbose))
diff --git a/MinGW/Options.td b/MinGW/Options.td
index 95b61952fc5e..222121663921 100644
--- a/MinGW/Options.td
+++ b/MinGW/Options.td
@@ -45,6 +45,9 @@ def exclude_all_symbols: F<"exclude-all-symbols">,
     HelpText<"Don't automatically export any symbols">;
 def export_all_symbols: F<"export-all-symbols">,
     HelpText<"Export all symbols even if a def file or dllexport attributes are used">;
+defm fatal_warnings: B<"fatal-warnings",
+    "Treat warnings as errors",
+    "Do not treat warnings as errors (default)">;
 defm file_alignment: Eq<"file-alignment", "Set file alignment">;
 defm gc_sections: B<"gc-sections",
     "Remove unused sections",
diff --git a/test/MinGW/driver.test b/test/MinGW/driver.test
index 33503d45189e..c8b7e2d12deb 100644
--- a/test/MinGW/driver.test
+++ b/test/MinGW/driver.test
@@ -294,3 +294,12 @@ DEMANGLE: -demangle{{ }}
 RUN: ld.lld -### -m i386pep foo.o -no-demangle | FileCheck -check-prefix NO-DEMANGLE %s
 RUN: ld.lld -### -m i386pep foo.o --no-demangle | FileCheck -check-prefix NO-DEMANGLE %s
 NO-DEMANGLE: -demangle:no
+
+RUN: ld.lld -### -m i386pep foo.o -fatal-warnings | FileCheck -check-prefix FATAL_WARNINGS %s
+RUN: ld.lld -### -m i386pep foo.o --fatal-warnings | FileCheck -check-prefix FATAL_WARNINGS %s
+FATAL_WARNINGS: -WX{{ }}
+
+RUN: ld.lld -### -m i386pep foo.o | FileCheck -check-prefix NO-FATAL_WARNINGS %s
+RUN: ld.lld -### -m i386pep foo.o -no-fatal-warnings | FileCheck -check-prefix NO-FATAL_WARNINGS %s
+RUN: ld.lld -### -m i386pep foo.o --no-fatal-warnings | FileCheck -check-prefix NO-FATAL_WARNINGS %s
+NO-FATAL_WARNINGS: -WX:no
-- 
2.31.1.windows.1

