LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 19744 - FileCheck mishandles buffering on Windows when Cygwin is on PATH?
Summary: FileCheck mishandles buffering on Windows when Cygwin is on PATH?
Status: RESOLVED WONTFIX
Alias: None
Product: Test Suite
Classification: Unclassified
Component: lit (show other bugs)
Version: trunk
Hardware: PC Windows NT
: P normal
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-05-14 14:44 PDT by Timur Iskhodzhanov
Modified: 2014-05-27 15:47 PDT (History)
8 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Timur Iskhodzhanov 2014-05-14 14:44:46 PDT
Steps to repro as of r208805:
1) Have LLVM+Clang+compiler-rt checkout on a Windows machine

2) Do a cmake/ninja build

4) Put cygwin at the end of your PATH like so:
$ set PATH=%PATH%;C:\cygwin\bin

3) Run
$ python bin\llvm-lit.py -v projects\compiler-rt\test\asan\32bitConfig\TestCases --filter=thread_stack
and make sure it passes

4) Apply the following simple patch to compiler-rt:
diff --git lib/sanitizer_common/sanitizer_win.cc lib/sanitizer_common/sanitizer_win.cc
index ec6ce99..f82f78e 100644
--- lib/sanitizer_common/sanitizer_win.cc
+++ lib/sanitizer_common/sanitizer_win.cc
@@ -304,6 +304,7 @@ uptr internal_write(fd_t fd, const void *buf, uptr count) {
   }

   DWORD ret;
+  Sleep(100);  // Make the failure stable rather than flaky.
   if (WriteFile(output_stream, buf, count, &ret, 0))
     return ret;

diff --git test/asan/TestCases/Windows/thread_stack_array_left_oob.cc test/asan/TestCases/Windows/thread_stack_array_left_oob.cc
index 31a58bb..e6db163 100644
--- test/asan/TestCases/Windows/thread_stack_array_left_oob.cc
+++ test/asan/TestCases/Windows/thread_stack_array_left_oob.cc
@@ -1,7 +1,7 @@
 // RUN: %clangxx_asan -O0 %s -Fe%t 2>&1
 // 'cat' is used below to work around FileCheck buffering bug which makes this
 // test flaky.  FIXME: file an issue.
-// RUN: not %run %t 2>&1 | cat | FileCheck %s
+// RUN: not %run %t 2>&1 | FileCheck %s

 #include <windows.h>

5) Run the same test again.

I observe a failure like this:
Command Output (stderr):
--
projects/compiler-rt/test/asan/TestCases/Windows/thread_stack_array_left_oob.cc:12:11: error: expected string not found in input
// CHECK: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
          ^
<stdin>:1:1: note: scanning from here
=================================================================
^

--

********************
Testing Time: 5.02s
********************
Failing Tests (1):
    AddressSanitizer32 :: TestCases/Windows/thread_stack_array_left_oob.cc

It looks like the pipe between the binary and FileCheck gets interrupted without waiting for the writer process to finish/close it.
Comment 1 Timur Iskhodzhanov 2014-05-14 14:46:00 PDT
FTR, I can't repro that without Cygwin on the PATH.
Comment 2 Timur Iskhodzhanov 2014-05-15 03:30:40 PDT
Alp wrote:
> Have you tried this test with and without the lit integrated shell?
> That seems a more likely culprit than FileCheck.

Did you mean with/without Cygwin? (see comment 1)
Or should I pass some particular flag to lit?
Comment 3 Timur Iskhodzhanov 2014-05-23 05:55:15 PDT
Any ideas?
Comment 4 NAKAMURA Takumi 2014-05-26 01:13:57 PDT
IMO, don't add cygwin in %PATH%. May I mark this as INVALID?
Comment 5 Timur Iskhodzhanov 2014-05-26 04:20:58 PDT
Ah, ok
http://llvm.org/docs/GettingStartedVS.html
now says "You will need GnuWin32 tools, too."

For some historical reason I believed it's Cygwin that's required to run the tests on Windows.
Comment 6 Reid Kleckner 2014-05-27 15:47:37 PDT
I've previously been able to run these tests with Cygwin tools and mostly everything works as long as you don't use Cygwin *bash*.  Instead, we use lit's shell interpreter, which works pretty well.

I'm going to try check-asan after all the cat removing commits and share my results.