diff --git a/llvm/test/tools/llvm-ml/basic.test b/llvm/test/tools/llvm-ml/basic.test --- 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 --check-prefix=BADFLAG %s # ENOENT-NOT: nologo # ENOENT: {{.*}}.blah.asm: [[MSG]] +# ENOENT-TA: /nnlogo: [[MSG]] +# BADFLAG: llvm-ml: error: invalid option '/nnlogo', 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 --- 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 --- a/llvm/test/tools/llvm-ml/lit.local.cfg +++ b/llvm/test/tools/llvm-ml/lit.local.cfg @@ -3,5 +3,4 @@ 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 --- /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 --- 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 --- a/llvm/tools/llvm-ml/Opts.td +++ b/llvm/tools/llvm-ml/Opts.td @@ -31,7 +31,7 @@ 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 @@ "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; def parse_only : MLFlag<"Zs">, HelpText<"Run a syntax-check only">, Alias, AliasArgs<["null"]>; diff --git a/llvm/tools/llvm-ml/llvm-ml.cpp b/llvm/tools/llvm-ml/llvm-ml.cpp --- a/llvm/tools/llvm-ml/llvm-ml.cpp +++ b/llvm/tools/llvm-ml/llvm-ml.cpp @@ -39,6 +39,7 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" #include "llvm/Support/Process.h" +#include "llvm/Support/Regex.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/TargetSelect.h" #include "llvm/Support/ToolOutputFile.h" @@ -206,18 +207,20 @@ T.ParseArgs(ArgsArr, MissingArgIndex, MissingArgCount); std::string InputFilename; + llvm::Regex SlashFlagRegex("^\\/[^\\/]+$"); 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; " << "ignoring '" << InputFilename << "'\n"; } InputFilename = ArgString; - } else { + } else if (SlashFlagRegex.match(ArgString)) { std::string Diag; raw_string_ostream OS(Diag); OS << "invalid option '" << ArgString << "'"; @@ -228,6 +231,9 @@ WithColor::error(errs(), ProgName) << OS.str() << '\n'; exit(1); + } else { + WithColor::error() << ArgString << ": " << IsFileEC.message() << '\n'; + exit(1); } } for (auto *Arg : InputArgs.filtered(OPT_assembly_file)) {