Index: llvm/lib/Option/OptTable.cpp =================================================================== --- llvm/lib/Option/OptTable.cpp +++ llvm/lib/Option/OptTable.cpp @@ -455,6 +455,7 @@ MissingArgIndex = MissingArgCount = 0; unsigned Index = 0, End = ArgArr.size(); + bool SeenAllOptions = false; while (Index < End) { // Ingore nullptrs, they are response file's EOL markers if (Args.getArgString(Index) == nullptr) { @@ -468,10 +469,26 @@ continue; } + // "--" on its own marks the end of option parsing, anything afterwards + // should be treated as a positional input. + if (Str == "--") { + SeenAllOptions = true; + ++Index; + continue; + } + unsigned Prev = Index; - std::unique_ptr A = GroupedShortOptions - ? parseOneArgGrouped(Args, Index) - : ParseOneArg(Args, Index, FlagsToInclude, FlagsToExclude); + std::unique_ptr A; + if (SeenAllOptions) { + A = std::make_unique(getOption(InputOptionID), Str, Index, + Args.getArgString(Index)); + ++Index; + } else { + A = GroupedShortOptions + ? parseOneArgGrouped(Args, Index) + : ParseOneArg(Args, Index, FlagsToInclude, FlagsToExclude); + } + assert((Index > Prev || GroupedShortOptions) && "Parser failed to consume argument."); Index: llvm/test/tools/llvm-nm/option--.test =================================================================== --- /dev/null +++ llvm/test/tools/llvm-nm/option--.test @@ -0,0 +1,10 @@ +; RUN: not llvm-nm -- -weird-filename-that-doesnt-exist 2>&1 | FileCheck %s --check-prefix=CHECK-NOTOPT +; CHECK-NOTOPT: error: -weird-filename-that-doesnt-exist: No such file or directory + +; RUN: llvm-as < %s > %p/-.bc +; RUN: llvm-nm -- %p/-.bc | FileCheck %s + +; CHECK: foo +define void @foo() { + ret void +}