Skip to content

clang-repl output differences on Windows when piped into something else #143547

Open
@DavidSpickett

Description

@DavidSpickett

Relates to #127467.

Where we saw the added test case failing on Windows on Arm and Windows x64.

https://lab.llvm.org/buildbot/#/builders/161/builds/6473
https://lab.llvm.org/buildbot/#/builders/63/builds/7023

Exit Code: 1
Command Output (stdout):
--
# RUN: at line 3
cat C:\Users\tcwg\llvm-worker\clang-arm64-windows-msvc\llvm-project\clang\test\Interpreter\lambda.cpp | c:\users\tcwg\llvm-worker\clang-arm64-windows-msvc\build\bin\clang-repl.exe | c:\users\tcwg\llvm-worker\clang-arm64-windows-msvc\build\bin\filecheck.exe C:\Users\tcwg\llvm-worker\clang-arm64-windows-msvc\llvm-project\clang\test\Interpreter\lambda.cpp
# executed command: cat 'C:\Users\tcwg\llvm-worker\clang-arm64-windows-msvc\llvm-project\clang\test\Interpreter\lambda.cpp'
# executed command: 'c:\users\tcwg\llvm-worker\clang-arm64-windows-msvc\build\bin\clang-repl.exe'
# .---command stderr------------
# | In file included from <<< inputs >>>:1:
# | input_line_22:1:17: error: non-local lambda expression cannot have a capture-default
# |     1 | auto capture = [&]() { return x * 2; };
# |       |                 ^
# | error: Parsing failed.
# `-----------------------------
# executed command: 'c:\users\tcwg\llvm-worker\clang-arm64-windows-msvc\build\bin\filecheck.exe' 'C:\Users\tcwg\llvm-worker\clang-arm64-windows-msvc\llvm-project\clang\test\Interpreter\lambda.cpp'
# RUN: at line 4
cat C:\Users\tcwg\llvm-worker\clang-arm64-windows-msvc\llvm-project\clang\test\Interpreter\lambda.cpp | c:\users\tcwg\llvm-worker\clang-arm64-windows-msvc\build\bin\clang-repl.exe -Xcc -Xclang -Xcc -verify -Xcc -O2 | c:\users\tcwg\llvm-worker\clang-arm64-windows-msvc\build\bin\filecheck.exe C:\Users\tcwg\llvm-worker\clang-arm64-windows-msvc\llvm-project\clang\test\Interpreter\lambda.cpp
# executed command: cat 'C:\Users\tcwg\llvm-worker\clang-arm64-windows-msvc\llvm-project\clang\test\Interpreter\lambda.cpp'
# executed command: 'c:\users\tcwg\llvm-worker\clang-arm64-windows-msvc\build\bin\clang-repl.exe' -Xcc -Xclang -Xcc -verify -Xcc -O2
# .---command stderr------------
# | error: Parsing failed.
# `-----------------------------
# executed command: 'c:\users\tcwg\llvm-worker\clang-arm64-windows-msvc\build\bin\filecheck.exe' 'C:\Users\tcwg\llvm-worker\clang-arm64-windows-msvc\llvm-project\clang\test\Interpreter\lambda.cpp'
# .---command stderr------------
# | C:\Users\tcwg\llvm-worker\clang-arm64-windows-msvc\llvm-project\clang\test\Interpreter\lambda.cpp:26:11: error: CHECK: expected string not found in input
# | // CHECK: x = 42
# |           ^
# | <stdin>:4:28: note: scanning from here
# | clang-repl> clang-repl> TWO
# |                            ^
# | <stdin>:5:9: note: possible intended match here
# | clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 
# |         ^
# | 
# | Input file: <stdin>
# | Check file: C:\Users\tcwg\llvm-worker\clang-arm64-windows-msvc\llvm-project\clang\test\Interpreter\lambda.cpp
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
# | <<<<<<
# |             1: x = 42 
# |             2: clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> ONE 
# |             3: clang-repl> clang-repl> TWO 
# |             4: clang-repl> clang-repl> TWO 
# | check:26'0                                X error: no match found
# |             5: clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl>  
# | check:26'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | check:26'1             ?                                                                                                                                                     possible intended match
# | >>>>>>
# `-----------------------------
# error: command failed with exit status: 1
--
********************

The PR is correct and so is the test case, on Linux and in pre-commit Windows CI.

Somehow on these buildbots, the output changes order when piped into something:

C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build>cat C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\clang\test\Interpreter\lambda.cpp | .\bin\clang-repl.exe -Xcc -Xclang -Xcc -verify -Xcc -O2
clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> ONE
clang-repl> clang-repl> TWO
clang-repl> clang-repl> TWO
clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> error: Parsing failed.
clang-repl> clang-repl> clang-repl> x = 42
clang-repl> clang-repl> clang-repl>

Note x = 42 is last, this is what we expect.

C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build>cat C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\clang\test\Interpreter\lambda.cpp | .\bin\clang-repl.exe -Xcc -Xclang -Xcc -verify -Xcc -O2 | cat
error: Parsing failed.
x = 42
clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> ONE
clang-repl> clang-repl> TWO
clang-repl> clang-repl> TWO
clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl>

Somehow x = 42 has now moved?

Linux does not show any difference:

$ cat ../llvm-project/clang/test/Interpreter/lambda.cpp | ./bin/clang-repl -Xcc -Xclang -Xcc -verify -Xcc -O2
ONE
TWO
TWO
error: Parsing failed.
x = 42
$ cat ../llvm-project/clang/test/Interpreter/lambda.cpp | ./bin/clang-repl -Xcc -Xclang -Xcc -verify -Xcc -O2 | cat
error: Parsing failed.
ONE
TWO
TWO
x = 42

Though, note that it does not print a clang-repl> for every line. So perhaps on Windows we are not detecting whether the output is interactive?

Even so, if the ordering is correct, it should not matter.

I can "fix" the test by passing -O0 instead of -O2. -O1 still fails. This might be Arm specific, not tried it on x86.

I can also "fix" the test by making the first two prints have formatting arguments. Even if they are constants:

auto l1 = []() { printf("ONE %s\n", ""); return 42; };

This makes me suspect puts vs. printf but I would have thought we could compile both to puts anyway.

Another suspect is the piping mechanism, or the cat binary we are using. Which comes from an install of git for windows.

The problem reproduces outside of lit, so if we are using lit's internal terminal here, whatever it's doing, the real terminal is doing the same thing.

(I'm not sure which one lit is using tbh)

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status

    Needs Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions