Bug 68580 - FAIL: c-c++-common/tsan/pr65400-1.c -O0 execution test
Summary: FAIL: c-c++-common/tsan/pr65400-1.c -O0 execution test
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: testsuite (show other bugs)
Version: 6.0
: P3 normal
Target Milestone: ---
Assignee: Bernd Edlinger
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-11-27 09:59 UTC by Tom de Vries
Modified: 2016-02-20 14:16 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
tentative patch (413 bytes, patch)
2016-02-12 17:05 UTC, Tom de Vries
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tom de Vries 2015-11-27 09:59:21 UTC
I can't yet reproduce this failure on the command line.

Still, it seems to happen once in a while, for -O2 here: https://gcc.gnu.org/ml/gcc-regression/2015-08/msg00147.html .

AFAIU, given the dg-shouldfail, the failure actually means that once in a while the executable succeeds and fails to give the expected warning and runtime error.

Expected warning (which is combined with return status 66):
...
==================
WARNING: ThreadSanitizer: data race (pid=17100)
  Read of size 4 at 0x000000601544 by thread T1:
    #0 baz3 src/gcc/testsuite/c-c++-common/tsan/pr65400-1.c:46 (pr65400-1.exe+0x000000400cbb)
    #1 baz5 src/gcc/testsuite/c-c++-common/tsan/pr65400-1.c:61 (pr65400-1.exe+0x000000400d71)
    #2 tf src/gcc/testsuite/c-c++-common/tsan/pr65400-1.c:68 (pr65400-1.exe+0x000000400d97)

  Previous write of size 4 at 0x000000601544 by main thread:
    #0 main src/gcc/testsuite/c-c++-common/tsan/pr65400-1.c:79 (pr65400-1.exe+0x000000400e12)

  Location is global 'v' of size 4 at 0x000000601544 (pr65400-1.exe+0x000000601544)

  Thread T1 (tid=17102, running) created by main thread at:
    #0 pthread_create src/libsanitizer/tsan/tsan_interceptors.cc:876 (libtsan.so.0+0x00000002af04)
    #1 main src/gcc/testsuite/c-c++-common/tsan/pr65400-1.c:77 (pr65400-1.exe+0x000000400dea)

SUMMARY: ThreadSanitizer: data race src/gcc/testsuite/c-c++-common/tsan/pr65400-1.c:46 in baz3
==================
ThreadSanitizer: reported 1 warnings
...
Comment 1 Tom de Vries 2015-11-27 10:37:20 UTC
(In reply to vries from comment #0)
> I can't yet reproduce this failure on the command line.

That includes 10000 iterations of running the executable, for both -O2 and -O0.
Comment 2 Dmitry Vyukov 2015-11-27 11:03:05 UTC
If you change types of:

int v;
int q;
int o;

to 'long long', does it fix the failure?
Comment 3 Tom de Vries 2015-11-27 11:10:15 UTC
(In reply to Dmitry Vyukov from comment #2)
> If you change types of:
> 
> int v;
> int q;
> int o;
> 
> to 'long long', does it fix the failure?

As long as I don't have a reliable way to reproduce the failure, I can't answer that question.
Comment 4 Tom de Vries 2015-12-01 10:44:41 UTC
I've observed this failure now in two seperate build & test runs.
Comment 5 Jeffrey A. Law 2016-02-01 22:04:29 UTC
Author: law
Date: Mon Feb  1 22:03:57 2016
New Revision: 233053

URL: https://gcc.gnu.org/viewcvs?rev=233053&root=gcc&view=rev
Log:
	PR tree-optimization/68580
	* params.def (FSM_MAXIMUM_PHI_ARGUMENTS): New param.
	* tree-ssa-threadbackward.c
	(fsm_find_control_statement_thread_paths): Do not try to walk
	through large PHI nodes.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/params.def
    trunk/gcc/tree-ssa-threadbackward.c
Comment 6 Tom de Vries 2016-02-02 07:36:28 UTC
https://gcc.gnu.org/ml/gcc-cvs/2016-02/msg00030.html :

Author: law
Date: Mon Feb  1 22:05:58 2016
New Revision: 233054

URL: https://gcc.gnu.org/viewcvs?rev=233054&root=gcc&view=rev
Log:
Fix PR # in last change

Modified:
    trunk/gcc/ChangeLog
Comment 7 Tom de Vries 2016-02-08 12:22:11 UTC
Ran into it once more while testing couple of patches on top of r233103.
Comment 8 Tom de Vries 2016-02-12 16:07:35 UTC
I managed to trigger the test returning 0 from the command line, by running it in parallel:
...
$ ( export LD_LIBRARY_PATH=$(pwd -P)/install/lib64; for cnt in $(seq 1 400); do (./a.out ; echo $? ) > log.$cnt 2>&1 & done )
$ egrep  '^0$' log.* | wc -l
54
...

I can't be sure if that is the reason that the test is failing (by returning 0) during running the testsuite, but it's certainly possible (I'm running it with -j12).

So, I suspect that the test fails because pthread_create fails with EAGAIN due to insufficient resources:
...
int
main ()
{
  pthread_t th;
  barrier_init (&barrier, 2);
  if (pthread_create (&th, NULL, tf, NULL))
    return 0;
...

Indeed in the testcase we do not distinguish between:
- return 0, case pthread_create failed, and
- return 0 at end of main, -fsanitize=thread failed to catch the race condition.

It would probably be good to print an error message when pthread_create fails, such that when looking at the fail in the testlog, we can easily see that that is the reason it failed, and not expect it to reproduce otherwise.
Comment 9 Tom de Vries 2016-02-12 17:05:25 UTC
Created attachment 37675 [details]
tentative patch
Comment 10 Tom de Vries 2016-02-15 06:01:53 UTC
posted RFC: https://gcc.gnu.org/ml/gcc-patches/2016-02/msg00949.html
Comment 11 Tom de Vries 2016-02-18 11:31:13 UTC
Alternative patch proposed by Bernd Edlinger : https://gcc.gnu.org/ml/gcc-patches/2016-02/msg00976.html .

Patch approved by sanitizer reviewer : https://gcc.gnu.org/ml/gcc-patches/2016-02/msg00985.html .
Comment 12 Bernd Edlinger 2016-02-18 22:27:41 UTC
Author: edlinger
Date: Thu Feb 18 22:27:09 2016
New Revision: 233538

URL: https://gcc.gnu.org/viewcvs?rev=233538&root=gcc&view=rev
Log:
PR testsuite/68580
* c-c++-common/tsan/pr65400-1.c (v, q, o): Make 8-byte aligned.

Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/c-c++-common/tsan/pr65400-1.c
Comment 13 Bernd Edlinger 2016-02-20 05:58:32 UTC
Author: edlinger
Date: Sat Feb 20 05:58:00 2016
New Revision: 233581

URL: https://gcc.gnu.org/viewcvs?rev=233581&root=gcc&view=rev
Log:
2016-02-20  Bernd Edlinger  <bernd.edlinger@hotmail.de>

        Backport from mainline
        2016-02-18  Bernd Edlinger  <bernd.edlinger@hotmail.de>

        PR testsuite/68580
        * c-c++-common/tsan/pr65400-1.c (v, q, o): Make 8-byte aligned.

Modified:
    branches/gcc-5-branch/gcc/testsuite/ChangeLog
    branches/gcc-5-branch/gcc/testsuite/c-c++-common/tsan/pr65400-1.c
Comment 14 Tom de Vries 2016-02-20 14:16:57 UTC
Patch with testcase fix committed to trunk and 5 branch. Testcase not present in 4.9 branch.

Marking resolved-fixed.