[llvm] 0499a9d - [ms] [llvm-ml] Accept /WX to signal that warnings should be fatal.

Eric Astor via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 2 12:13:30 PDT 2021


Author: Eric Astor
Date: 2021-04-02T15:13:20-04:00
New Revision: 0499a9d6889050c4b28c0d6d9ec987831ad7de7e

URL: https://github.com/llvm/llvm-project/commit/0499a9d6889050c4b28c0d6d9ec987831ad7de7e
DIFF: https://github.com/llvm/llvm-project/commit/0499a9d6889050c4b28c0d6d9ec987831ad7de7e.diff

LOG: [ms] [llvm-ml] Accept /WX to signal that warnings should be fatal.

Define -fatal-warnings to make warnings fatal, and accept /WX as an ML.EXE compatible alias for it.

Also make sure that if Warning() returns true, we always treat it as an error.

Reviewed By: thakis

Differential Revision: https://reviews.llvm.org/D92504

Added: 
    llvm/test/tools/llvm-ml/hexfloat_error.asm
    llvm/test/tools/llvm-ml/hexfloat_warn.asm

Modified: 
    llvm/lib/MC/MCParser/MasmParser.cpp
    llvm/tools/llvm-ml/Opts.td
    llvm/tools/llvm-ml/llvm-ml.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/MCParser/MasmParser.cpp b/llvm/lib/MC/MCParser/MasmParser.cpp
index b3c854c136d1..4097f820f839 100644
--- a/llvm/lib/MC/MCParser/MasmParser.cpp
+++ b/llvm/lib/MC/MCParser/MasmParser.cpp
@@ -4473,8 +4473,9 @@ bool MasmParser::parseDirectiveAlign() {
     return addErrorSuffix(" in align directive");
   // Ignore empty 'align' directives.
   if (getTok().is(AsmToken::EndOfStatement)) {
-    Warning(AlignmentLoc, "align directive with no operand is ignored");
-    return parseToken(AsmToken::EndOfStatement);
+    return Warning(AlignmentLoc,
+                   "align directive with no operand is ignored") &&
+           parseToken(AsmToken::EndOfStatement);
   }
   if (parseAbsoluteExpression(Alignment) ||
       parseToken(AsmToken::EndOfStatement))

diff  --git a/llvm/test/tools/llvm-ml/hexfloat_error.asm b/llvm/test/tools/llvm-ml/hexfloat_error.asm
new file mode 100644
index 000000000000..d917529540d5
--- /dev/null
+++ b/llvm/test/tools/llvm-ml/hexfloat_error.asm
@@ -0,0 +1,10 @@
+; RUN: not llvm-ml -filetype=s %s /WX /Fo /dev/null 2>&1 | FileCheck %s --implicit-check-not=error:
+
+.data
+
+; CHECK: :[[# @LINE + 1]]:25: error: MASM-style hex floats ignore explicit sign
+negative_hexfloat REAL4 -3fa66666r
+
+.code
+
+END

diff  --git a/llvm/test/tools/llvm-ml/hexfloat_warn.asm b/llvm/test/tools/llvm-ml/hexfloat_warn.asm
new file mode 100644
index 000000000000..5ba3083af7da
--- /dev/null
+++ b/llvm/test/tools/llvm-ml/hexfloat_warn.asm
@@ -0,0 +1,12 @@
+; RUN: llvm-ml -filetype=s %s /Fo - 2>&1 | FileCheck %s
+
+.data
+
+; CHECK: :[[# @LINE + 1]]:25: warning: MASM-style hex floats ignore explicit sign
+negative_hexfloat REAL4 -3fa66666r
+; CHECK-LABEL: negative_hexfloat:
+; CHECK-NEXT: .long 1067869798
+
+.code
+
+END

diff  --git a/llvm/tools/llvm-ml/Opts.td b/llvm/tools/llvm-ml/Opts.td
index a78072007e92..b5ba920c8769 100644
--- a/llvm/tools/llvm-ml/Opts.td
+++ b/llvm/tools/llvm-ml/Opts.td
@@ -31,6 +31,8 @@ def bitness : LLVMJoined<"m">, Values<"32,64">,
               HelpText<"Target platform (x86 or x86-64)">;
 def as_lex : LLVMFlag<"as-lex">,
              HelpText<"Lex tokens from a .asm file without assembling">;
+def fatal_warnings : LLVMFlag<"fatal-warnings">,
+                     HelpText<"Treat warnings as errors">;
 def filetype : LLVMJoined<"filetype=">, Values<"obj,s,null">,
                HelpText<"Emit a file with the given type">;
 def output_att_asm : LLVMFlag<"output-att-asm">,
@@ -68,6 +70,7 @@ def safeseh : MLFlag<"safeseh">,
 def assembly_file : MLJoinedOrSeparate<"Ta">,
                     HelpText<"Assemble source file with name not ending with "
                              "the .asm extension">;
+def error_on_warning : MLFlag<"WX">, Alias<fatal_warnings>;
 def parse_only : MLFlag<"Zs">, HelpText<"Run a syntax-check only">,
                  Alias<filetype>, AliasArgs<["null"]>;
 
@@ -102,7 +105,6 @@ def listing_title : UnsupportedSeparate<"St">, HelpText<"">;
 def listing_false_conditionals : UnsupportedFlag<"Sx">, HelpText<"">;
 def extra_warnings : UnsupportedFlag<"w">, HelpText<"">;
 def warning_level : UnsupportedJoined<"W">, HelpText<"">;
-def error_on_warning : UnsupportedFlag<"WX">, HelpText<"">;
 def ignore_include_envvar : UnsupportedFlag<"X">, HelpText<"">;
 def line_number_info : UnsupportedFlag<"Zd">, HelpText<"">;
 def export_all_symbols : UnsupportedFlag<"Zf">, HelpText<"">;

diff  --git a/llvm/tools/llvm-ml/llvm-ml.cpp b/llvm/tools/llvm-ml/llvm-ml.cpp
index 1733dcd47281..1292f40eaa32 100644
--- a/llvm/tools/llvm-ml/llvm-ml.cpp
+++ b/llvm/tools/llvm-ml/llvm-ml.cpp
@@ -231,6 +231,7 @@ int main(int Argc, char **Argv) {
 
   MCTargetOptions MCOptions;
   MCOptions.AssemblyLanguage = "masm";
+  MCOptions.MCFatalWarnings = InputArgs.hasArg(OPT_fatal_warnings);
 
   Triple TheTriple = GetTriple(ProgName, InputArgs);
   std::string Error;


        


More information about the llvm-commits mailing list