Bug 60658 - [4.7/4.8/4.9 Regression] std::atomic<T*> is unexpectedly not lock-free
Summary: [4.7/4.8/4.9 Regression] std::atomic<T*> is unexpectedly not lock-free
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: 4.7.4
Assignee: Jonathan Wakely
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-03-25 17:07 UTC by Paul Pluzhnikov
Modified: 2014-03-25 20:42 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work: 4.6.3
Known to fail: 4.7.3, 4.8.2
Last reconfirmed: 2014-03-25 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Pluzhnikov 2014-03-25 17:07:33 UTC
Using current trunk (r208813):

g++ -std=c++11 atomic.cc -latomic && ./a.out
a.out: atomic.cc:20: int main(): Assertion `b.is_lock_free()' failed.

As far as I can tell, this is happening because

  std::__atomic_base<Bar*>::_M_type_size()

returns sizeof(Bar) instead of returning sizeof(Bar*).


// atomic.cc
#include <atomic>
#include <assert.h>

struct Foo {
  char buf[1];
};

struct Bar {
  char buf[100];
};


int
main ()
{
  std::atomic<Foo*> a;
  assert (a.is_lock_free());

  std::atomic<Bar*> b;
  assert (b.is_lock_free());
}


Google ref: b/13626319
Comment 1 Jonathan Wakely 2014-03-25 18:45:35 UTC
Oops - I thought we'd fixed all those kind of bugs in the atomic<T*> specialization
Comment 2 Jonathan Wakely 2014-03-25 19:29:03 UTC
This is a regression in all active branches
Comment 3 Jonathan Wakely 2014-03-25 19:40:24 UTC
Author: redi
Date: Tue Mar 25 19:39:52 2014
New Revision: 208819

URL: http://gcc.gnu.org/viewcvs?rev=208819&root=gcc&view=rev
Log:
	PR libstdc++/60658
	* include/bits/atomic_base.h (__atomic_base<_PTp*>::is_lock_free()):
	Use sizeof pointer type not the element type.
	* testsuite/29_atomics/atomic/60658.cc: New.

Added:
    trunk/libstdc++-v3/testsuite/29_atomics/atomic/60658.cc
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/bits/atomic_base.h
Comment 4 Jonathan Wakely 2014-03-25 20:14:18 UTC
Author: redi
Date: Tue Mar 25 20:13:46 2014
New Revision: 208820

URL: http://gcc.gnu.org/viewcvs?rev=208820&root=gcc&view=rev
Log:
	PR libstdc++/60658
	* include/bits/atomic_base.h (__atomic_base<_PTp*>::is_lock_free()):
	Use sizeof pointer type not the element type.
	* testsuite/29_atomics/atomic/60658.cc: New.

	PR libstdc++/60658
	* include/bits/atomic_base.h (__atomic_base<_PTp*>::is_lock_free()):
	Use sizeof pointer type not the element type.
	* testsuite/29_atomics/atomic/60658.cc: New.

Added:
    branches/gcc-4_8-branch/libstdc++-v3/testsuite/29_atomics/atomic/60658.cc
Modified:
    branches/gcc-4_8-branch/libstdc++-v3/ChangeLog
    branches/gcc-4_8-branch/libstdc++-v3/include/bits/atomic_base.h
Comment 5 Jonathan Wakely 2014-03-25 20:40:50 UTC
Author: redi
Date: Tue Mar 25 20:40:17 2014
New Revision: 208821

URL: http://gcc.gnu.org/viewcvs?rev=208821&root=gcc&view=rev
Log:
	PR libstdc++/60658
	* include/bits/atomic_base.h (__atomic_base<_PTp*>::is_lock_free()):
	Use sizeof pointer type not the element type.
	* testsuite/29_atomics/atomic/60658.cc: New.

Added:
    branches/gcc-4_7-branch/libstdc++-v3/testsuite/29_atomics/atomic/60658.cc
Modified:
    branches/gcc-4_7-branch/libstdc++-v3/ChangeLog
    branches/gcc-4_7-branch/libstdc++-v3/include/bits/atomic_base.h
Comment 6 Jonathan Wakely 2014-03-25 20:42:21 UTC
Fixed for 4.7.4, 4.8.3 and 4.9.0