Bug 81316 - Missing memory side effect on __atomic_store
Summary: Missing memory side effect on __atomic_store
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 6.3.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on: 80640
Blocks:
  Show dependency treegraph
 
Reported: 2017-07-04 19:34 UTC by Muhammad Faiz
Modified: 2017-09-04 10:19 UTC (History)
1 user (show)

See Also:
Host:
Target: x86_64-redhat-linux
Build: x86_64-redhat-linux
Known to work:
Known to fail:
Last reconfirmed: 2017-07-17 00:00:00


Attachments
Testcase (331 bytes, text/plain)
2017-07-04 19:34 UTC, Muhammad Faiz
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Muhammad Faiz 2017-07-04 19:34:44 UTC
Created attachment 41679 [details]
Testcase

Missing memory side effect on __atomic_store using __ATOMIC_RELEASE.

How to reproduce (atomic-fail.c attached):
gcc atomic-fail.c -O2 -pthread -o atomic-fail
./atomic-fail
Error: val != 1, missing memory side effect.


The bug is not reproduced with __atomic_store using __ATOMIC_SEQ_CST. Probably this is similar to Bug80640.
Comment 1 Alexander Monakov 2017-07-17 09:48:24 UTC
Yes, it's a similar target-specific issue, and I've noticed it when writing a patch for PR 80640. At least x86 and s390 exhibit it. Perhaps it's better to fix it in the middle-end (i.e. expand) though, rather than require backends DTRT.

I've submitted a partial patch for this issue here: https://gcc.gnu.org/ml/gcc-patches/2017-05/msg00786.html but at the moment both remain unreviewed. It also wouldn't fix this testcase, because I didn't notice that x86 used UNSPEC on the RHS (i.e. not the memory operand) of the store, so I added compiler barriers only for loads (more reason to fix it in expand, I guess).

(the testcase formally invokes undefined behavior by entering an infinite loop without side effects)
Comment 2 Alexander Monakov 2017-09-04 10:17:08 UTC
Author: amonakov
Date: Mon Sep  4 10:16:37 2017
New Revision: 251643

URL: https://gcc.gnu.org/viewcvs?rev=251643&root=gcc&view=rev
Log:
optabs: ensure atomic_load/stores have compiler barriers

	PR rtl-optimization/57448
	PR target/67458
	PR target/81316
	* optabs.c (expand_atomic_load): Place compiler memory barriers if
	using atomic_load pattern.
	(expand_atomic_store): Likewise.
testsuite/
	* gcc.dg/atomic/pr80640-2.c: New testcase.
	* gcc.dg/atomic/pr81316.c: New testcase.


Added:
    trunk/gcc/testsuite/gcc.dg/atomic/pr80640-2.c
    trunk/gcc/testsuite/gcc.dg/atomic/pr81316.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/optabs.c
    trunk/gcc/testsuite/ChangeLog
Comment 3 Alexander Monakov 2017-09-04 10:19:31 UTC
Fixed.