<div dir="ltr">Did you file an upstream bug?</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jun 4, 2014 at 10:04 PM, Zachary Turner <span dir="ltr"><<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi rnk,<br>
<br>
Due to what can only be described as a CRT bug, stdout and amazingly even stderr are not always flushed upon process termination, especially when the system is under high threading pressure.  I have found two repros for this:<br>

<br>
1) In lib\Support\Threading.cpp, change sys::Mutex to an std::recursive_mutex and run check-clang.  Usually between 30 and 40 tests will fail.<br>
2) Add OutputDebugStrings in code that runs during static initialization and static shutdown.  This will sometimes generate similar failures.<br>
<br>
After a substantial amount of troubleshooting and debugging, I found that I could reproduce this from the command line without running check-clang.  Simply make the mutex change described in #1, then manually run the following command many times by running it once, then pressing Up -> Enter very quickly:<br>

<br>
D:\src\llvm\build\vs2013\Debug\bin\c-index-test.EXE -cursor-at=D:\src\llvm\tools\clang\test\Index\targeted-preamble.h:2:15 D:\src\llvm\tools\clang\test\Index\targeted-cursor.c -include D:\src\llvm\build\vs2013\tools\clang\test\Index\Output\targeted-cursor.c.tmp.h -Xclang<br>

-error-on-deserialized-decl=NestedVar1      -Xclang -error-on-deserialized-decl=TopVar    | D:\src\llvm\build\vs2013\Debug\bin\FileCheck.EXE D:\src\llvm\tools\clang\test\Index\targeted-cursor.c -check-prefix=PREAMBLE-CURSOR1<br>

<br>
Sporadically they will fail, and attaching a debugger to a failed instance indicates that stdin of FileCheck.exe is empty.<br>
<br>
Note that due to the repro in #2, we can rule out a bug in the STL's mutex implementation, and instead conclude that this is a real flake in the windows test harness.<br>
<br>
<a href="http://reviews.llvm.org/D4021" target="_blank">http://reviews.llvm.org/D4021</a><br>
<br>
Files:<br>
  tools/c-arcmt-test/c-arcmt-test.c<br>
  tools/c-index-test/c-index-test.c<br>
<br>
Index: tools/c-arcmt-test/c-arcmt-test.c<br>
===================================================================<br>
--- tools/c-arcmt-test/c-arcmt-test.c<br>
+++ tools/c-arcmt-test/c-arcmt-test.c<br>
@@ -97,14 +97,20 @@<br>
 void thread_runner(void *client_data_v) {<br>
   thread_info *client_data = client_data_v;<br>
   client_data->result = carcmttest_main(client_data->argc, client_data->argv);<br>
-#ifdef __CYGWIN__<br>
-  fflush(stdout);  /* stdout is not flushed on Cygwin. */<br>
-#endif<br>
+}<br>
+<br>
+static void flush_atexit(void) {<br>
+  // stdout, and surprisingly even stderr, are not always flushed on process<br>
+  // and thread exit, particularly when the system is under heavy load.<br>
+  fflush(stdout);<br>
+  fflush(stderr);<br>
 }<br>
<br>
 int main(int argc, const char **argv) {<br>
   thread_info client_data;<br>
<br>
+  atexit(flush_atexit);<br>
+<br>
 #if defined(_WIN32)<br>
   if (getenv("LIBCLANG_LOGGING") == NULL)<br>
     putenv("LIBCLANG_LOGGING=1");<br>
Index: tools/c-index-test/c-index-test.c<br>
===================================================================<br>
--- tools/c-index-test/c-index-test.c<br>
+++ tools/c-index-test/c-index-test.c<br>
@@ -4116,14 +4116,20 @@<br>
 void thread_runner(void *client_data_v) {<br>
   thread_info *client_data = client_data_v;<br>
   client_data->result = cindextest_main(client_data->argc, client_data->argv);<br>
-#ifdef __CYGWIN__<br>
-  fflush(stdout);  /* stdout is not flushed on Cygwin. */<br>
-#endif<br>
+}<br>
+<br>
+static void flush_atexit(void) {<br>
+  // stdout, and surprisingly even stderr, are not always flushed on process<br>
+  // and thread exit, particularly when the system is under heavy load.<br>
+  fflush(stdout);<br>
+  fflush(stderr);<br>
 }<br>
<br>
 int main(int argc, const char **argv) {<br>
   thread_info client_data;<br>
<br>
+  atexit(flush_atexit);<br>
+<br>
 #ifdef CLANG_HAVE_LIBXML<br>
   LIBXML_TEST_VERSION<br>
 #endif<br>
<br>_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
<br></blockquote></div><br></div>