https://github.com/boomanaiden154 created https://github.com/llvm/llvm-project/pull/158447
cat with no files passed to it is supposed to read from STDIN according to POSIX. The builtin cat lacking this behavior led to the clang test in dev-fd-fs.c to fail because it expected this behavior. This is a simple modification and I do not think it is possible to rewrite the test without this easily while preserving the semantics around named pipes. >From 5bd8d4f925f3b5f82d85ef693861b6b1067d9f38 Mon Sep 17 00:00:00 2001 From: Aiden Grossman <[email protected]> Date: Sat, 13 Sep 2025 22:54:58 +0000 Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?= =?UTF-8?q?l=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.6 --- clang/test/Misc/dev-fd-fs.c | 1 - llvm/utils/lit/lit/builtin_commands/cat.py | 3 +++ llvm/utils/lit/tests/Inputs/shtest-cat/cat.txt | 4 ++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/clang/test/Misc/dev-fd-fs.c b/clang/test/Misc/dev-fd-fs.c index ea94d950b0716..b989ab8a439cf 100644 --- a/clang/test/Misc/dev-fd-fs.c +++ b/clang/test/Misc/dev-fd-fs.c @@ -1,6 +1,5 @@ // Check that we can operate on files from /dev/fd. // REQUIRES: dev-fd-fs -// REQUIRES: shell // Check reading from named pipes. We cat the input here instead of redirecting // it to ensure that /dev/fd/0 is a named pipe, not just a redirected file. diff --git a/llvm/utils/lit/lit/builtin_commands/cat.py b/llvm/utils/lit/lit/builtin_commands/cat.py index ddab555662045..2797e0cbb4154 100644 --- a/llvm/utils/lit/lit/builtin_commands/cat.py +++ b/llvm/utils/lit/lit/builtin_commands/cat.py @@ -49,6 +49,9 @@ def main(argv): import os, msvcrt msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) + if len(filenames) == 0: + sys.stdout.write(sys.stdin.read()) + sys.exit(0) for filename in filenames: try: contents = None diff --git a/llvm/utils/lit/tests/Inputs/shtest-cat/cat.txt b/llvm/utils/lit/tests/Inputs/shtest-cat/cat.txt index 4014b0fca1f24..c5b5d247c2f95 100644 --- a/llvm/utils/lit/tests/Inputs/shtest-cat/cat.txt +++ b/llvm/utils/lit/tests/Inputs/shtest-cat/cat.txt @@ -70,3 +70,7 @@ # NP-CAT-OUTPUT-NEXT:M-HM-IM-JM-KM-LM-MM-NM-OM-PM-QM-RM-SM-TM-UM-VM-WM-XM-YM-ZM-[ # NP-CAT-OUTPUT-NEXT:M-\M-]M-^M-_M-`M-aM-bM-cM-dM-eM-fM-gM-hM-iM-jM-kM-lM-mM-nM-o # NP-CAT-OUTPUT-NEXT:M-pM-qM-rM-sM-tM-uM-vM-wM-xM-yM-zM-{M-|M-}M-~M-^? + +## Test that cat will pipe stdin to stdout if no other files are specified. +# RUN: echo test | cat | FileCheck --check-prefix=CAT-STDIN %s +# CAT-STDIN: test _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
