[llvm] ae38e48 - [llvm-ml] Remove all file extension restrictions

Alan Zhao via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 7 10:03:25 PDT 2022


Author: Alan Zhao
Date: 2022-06-07T13:03:19-04:00
New Revision: ae38e4880ec06bf4cfb7088fa66f70676701144c

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

LOG: [llvm-ml] Remove all file extension restrictions

After D126425 was submitted, hans@ observed that MSVC's ml.exe doesn't
care about the file's extension at all. Now, we check if the file exists
to determine whether an input filename is a valid assembly file.

To keep things consistent with clang-cl and lld-link, llvm-ml will treat
everything that's not a flag as a filename.

Reviewed By: hans

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

Added: 
    llvm/test/tools/llvm-ml/random_file_extension.blah

Modified: 
    llvm/test/tools/llvm-ml/basic.test
    llvm/test/tools/llvm-ml/lit.local.cfg
    llvm/tools/llvm-ml/Opts.td
    llvm/tools/llvm-ml/llvm-ml.cpp

Removed: 
    llvm/test/tools/llvm-ml/invalid_file_extension.blah
    llvm/test/tools/llvm-ml/valid_file_extension.S


################################################################################
diff  --git a/llvm/test/tools/llvm-ml/basic.test b/llvm/test/tools/llvm-ml/basic.test
index 736124cf110c2..27c457b7a37d8 100644
--- a/llvm/test/tools/llvm-ml/basic.test
+++ b/llvm/test/tools/llvm-ml/basic.test
@@ -1,4 +1,8 @@
 # RUN: not llvm-ml %t.blah.asm /nologo /Fo /dev/null 2>&1 | FileCheck -DMSG=%errc_ENOENT --check-prefix=ENOENT %s
+# RUN: not llvm-ml /Ta /nnlogo /Fo /dev/null 2>&1 | FileCheck -DMSG=%errc_ENOENT --check-prefix=ENOENT-TA %s
+# RUN: not llvm-ml - /Fo /dev/null /nnlogo 2>&1 | FileCheck -DMSG=%errc_ENOENT --check-prefix=ENOENT-FLAG %s
 
 # ENOENT-NOT: nologo
 # ENOENT: {{.*}}.blah.asm: [[MSG]]
+# ENOENT-TA: /nnlogo: [[MSG]]
+# ENOENT-FLAG: error: /nnlogo: [[MSG]], did you mean '/nologo'?

diff  --git a/llvm/test/tools/llvm-ml/invalid_file_extension.blah b/llvm/test/tools/llvm-ml/invalid_file_extension.blah
deleted file mode 100644
index 7b916910a1270..0000000000000
--- a/llvm/test/tools/llvm-ml/invalid_file_extension.blah
+++ /dev/null
@@ -1,8 +0,0 @@
-; RUN: not llvm-ml %s /Fo /dev/null 2>&1 | FileCheck %s --check-prefixes=CHECK-INVALID
-; RUN: llvm-ml /Ta %s -m64 -filetype=s /Fo - | FileCheck %s --check-prefixes=CHECK-TA
-
-; CHECK-INVALID: error: invalid option '{{.*}}invalid_file_extension.blah'
-
-.code
-foo:
-; CHECK-TA: foo:

diff  --git a/llvm/test/tools/llvm-ml/lit.local.cfg b/llvm/test/tools/llvm-ml/lit.local.cfg
index ffc3d7a1e0ab1..39c93fcfcb53e 100644
--- a/llvm/test/tools/llvm-ml/lit.local.cfg
+++ b/llvm/test/tools/llvm-ml/lit.local.cfg
@@ -3,5 +3,4 @@ if not ('X86' in config.root.targets):
     config.unsupported = True
 
 config.suffixes.add('.asm')
-config.suffixes.add('.S')
 config.suffixes.add('.blah')

diff  --git a/llvm/test/tools/llvm-ml/random_file_extension.blah b/llvm/test/tools/llvm-ml/random_file_extension.blah
new file mode 100644
index 0000000000000..d25ffc2d51f8e
--- /dev/null
+++ b/llvm/test/tools/llvm-ml/random_file_extension.blah
@@ -0,0 +1,6 @@
+; RUN: llvm-ml %s -m64 -filetype=s /Fo - | FileCheck %s
+; RUN: llvm-ml /Ta %s -m64 -filetype=s /Fo - | FileCheck %s
+
+.code
+foo:
+; CHECK: foo:

diff  --git a/llvm/test/tools/llvm-ml/valid_file_extension.S b/llvm/test/tools/llvm-ml/valid_file_extension.S
deleted file mode 100644
index 8c7e9435fed6c..0000000000000
--- a/llvm/test/tools/llvm-ml/valid_file_extension.S
+++ /dev/null
@@ -1,5 +0,0 @@
-; RUN: llvm-ml -m64 -filetype=s %s /Fo - | FileCheck %s
-
-.code
-foo:
-; CHECK: foo:

diff  --git a/llvm/tools/llvm-ml/Opts.td b/llvm/tools/llvm-ml/Opts.td
index 88897a7aa7c8f..686edded23b85 100644
--- a/llvm/tools/llvm-ml/Opts.td
+++ b/llvm/tools/llvm-ml/Opts.td
@@ -31,7 +31,7 @@ class UnsupportedSeparate<string name> : Separate<["/", "-"], name>,
 def bitness : LLVMJoined<"m">, Values<"32,64">,
               HelpText<"Target platform (x86 or x86-64)">;
 def as_lex : LLVMFlag<"as-lex">,
-             HelpText<"Lex tokens from an .asm or .S file without assembling">;
+             HelpText<"Lex tokens from a file without assembling">;
 def debug : LLVMFlag<"debug">, Flags<[HelpHidden]>,
             HelpText<"Enable debug output">;
 def debug_only : LLVMCommaJoined<"debug-only=">, Flags<[HelpHidden]>,
@@ -81,8 +81,8 @@ def safeseh : MLFlag<"safeseh">,
                        "that are all declared with .SAFESEH. Only available in "
                        "32-bit.">;
 def assembly_file : MLJoinedOrSeparate<"Ta">,
-                    HelpText<"Assemble source file with name not ending with "
-                             "the .asm or the .S extension">;
+                    HelpText<"Assemble source file with the given name. Used "
+                             "if the filename begins with a forward slash.">;
 def error_on_warning : MLFlag<"WX">, Alias<fatal_warnings>;
 def parse_only : MLFlag<"Zs">, HelpText<"Run a syntax-check only">,
                  Alias<filetype>, AliasArgs<["null"]>;

diff  --git a/llvm/tools/llvm-ml/llvm-ml.cpp b/llvm/tools/llvm-ml/llvm-ml.cpp
index 2651132f23ccc..12cd727e722a0 100644
--- a/llvm/tools/llvm-ml/llvm-ml.cpp
+++ b/llvm/tools/llvm-ml/llvm-ml.cpp
@@ -208,9 +208,10 @@ int main(int Argc, char **Argv) {
   std::string InputFilename;
   for (auto *Arg : InputArgs.filtered(OPT_INPUT)) {
     std::string ArgString = Arg->getAsString(InputArgs);
-    StringRef ArgStringRef(ArgString);
-    if (ArgString == "-" || ArgStringRef.endswith(".asm") ||
-        ArgStringRef.endswith(".S")) {
+    bool IsFile = false;
+    std::error_code IsFileEC =
+        llvm::sys::fs::is_regular_file(ArgString, IsFile);
+    if (ArgString == "-" || IsFile) {
       if (!InputFilename.empty()) {
         WithColor::warning(errs(), ProgName)
             << "does not support multiple assembly files in one command; "
@@ -220,7 +221,7 @@ int main(int Argc, char **Argv) {
     } else {
       std::string Diag;
       raw_string_ostream OS(Diag);
-      OS << "invalid option '" << ArgString << "'";
+      OS << ArgString << ": " << IsFileEC.message();
 
       std::string Nearest;
       if (T.findNearest(ArgString, Nearest) < 2)


        


More information about the llvm-commits mailing list