diff --git a/mlir/lib/Tools/mlir-query/MlirQueryMain.cpp b/mlir/lib/Tools/mlir-query/MlirQueryMain.cpp index 99500508ef045..6945c096124fd 100644 --- a/mlir/lib/Tools/mlir-query/MlirQueryMain.cpp +++ b/mlir/lib/Tools/mlir-query/MlirQueryMain.cpp @@ -21,6 +21,7 @@ #include "llvm/LineEditor/LineEditor.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/InitLLVM.h" +#include "llvm/Support/Process.h" #include "llvm/Support/SourceMgr.h" //===----------------------------------------------------------------------===// @@ -43,7 +44,7 @@ mlir::mlirQueryMain(int argc, char **argv, MLIRContext &context, llvm::cl::value_desc("command"), llvm::cl::cat(mlirQueryCategory)); static llvm::cl::opt inputFilename( - llvm::cl::Positional, llvm::cl::desc(""), + llvm::cl::Positional, llvm::cl::desc(""), llvm::cl::init("-"), llvm::cl::cat(mlirQueryCategory)); static llvm::cl::opt noImplicitModule{ @@ -68,6 +69,14 @@ mlir::mlirQueryMain(int argc, char **argv, MLIRContext &context, return mlir::success(); } + // When reading from stdin and the input is a tty, it is often a user mistake + // and the process "appears to be stuck". Print a message to let the user + // know! + if (inputFilename == "-" && + llvm::sys::Process::FileDescriptorIsDisplayed(fileno(stdin))) + llvm::errs() << "(processing input from stdin now, hit ctrl-c/ctrl-d to " + "interrupt)\n"; + // Set up the input file. std::string errorMessage; auto file = openInputFile(inputFilename, &errorMessage);