Index: llvm/test/tools/llvm-nm/warn-invalid-stdin.test =================================================================== --- /dev/null +++ llvm/test/tools/llvm-nm/warn-invalid-stdin.test @@ -0,0 +1,7 @@ +## Tests that when no input file is specified stdin is +## read but only when not reading from keyoard input. + +# RUN: not llvm-nm 2>&1 | FileCheck %s + +# CHECK: llvm-nm: warning: can't read from keyboard input. +# CHECK-NEXT: OVERVIEW: llvm symbol table dumper Index: llvm/tools/llvm-nm/llvm-nm.cpp =================================================================== --- llvm/tools/llvm-nm/llvm-nm.cpp +++ llvm/tools/llvm-nm/llvm-nm.cpp @@ -34,6 +34,7 @@ #include "llvm/Support/Format.h" #include "llvm/Support/InitLLVM.h" #include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/Process.h" #include "llvm/Support/Program.h" #include "llvm/Support/Signals.h" #include "llvm/Support/TargetSelect.h" @@ -1751,6 +1752,12 @@ } static void dumpSymbolNamesFromFile(std::string &Filename) { + if (sys::Process::StandardInIsUserInput()) { + WithColor::warning(outs(), ToolName) << "can't read from keyboard input.\n"; + cl::PrintHelpMessage(); + HadError = true; + return; + } ErrorOr> BufferOrErr = MemoryBuffer::getFileOrSTDIN(Filename); if (error(BufferOrErr.getError(), Filename)) @@ -2082,7 +2089,7 @@ if (OutputFormat == sysv || SizeSort) PrintSize = true; if (InputFilenames.empty()) - InputFilenames.push_back("a.out"); + InputFilenames.push_back("-"); if (InputFilenames.size() > 1) MultipleFiles = true;