From: Andrew MacLeod <amacleod@redhat.com>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH 5/5] Atomic type qualifier - Use atomic objects
Date: Tue, 30 Jul 2013 17:32:00 -0000 [thread overview]
Message-ID: <51F7F45D.9030400@redhat.com> (raw)
In-Reply-To: <51F7EE86.20805@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 207 bytes --]
This patch turns on the atomic qualifier for all C++ atomic objects
It also modifies a few testcases to ensure __attribute__((atomic)) and
_Atomic are recognized by the compiler and compile as expected.
[-- Attachment #2: f5.diff --]
[-- Type: text/x-patch, Size: 11840 bytes --]
libstdc++-v3
* include/bits/atomic_base.h (struct __atomic_base): Add
__attribute__((atomic) to member data element.
(struct __atomic_base<_PTp*>): Add __attribute__((atomic)) to member
data element.
* include/std/atomic (struct atomic): Add __attribute__((atomic)) to
member data element.
testsuite
* gcc.dg/atomic-exchange-{1-5}.c: Change atomic var to use
__attribute__((atomic)).
* gcc.dg/atomic-op-{1-5}.c: Add --std=c11 and change atomic var to
use _Atomic keyword.
Index: libstdc++-v3/include/bits/atomic_base.h
===================================================================
*** libstdc++-v3/include/bits/atomic_base.h (revision 201248)
--- libstdc++-v3/include/bits/atomic_base.h (working copy)
*************** _GLIBCXX_BEGIN_NAMESPACE_VERSION
*** 346,361 ****
// atomic_char32_t char32_t
// atomic_wchar_t wchar_t
//
! // NB: Assuming _ITp is an integral scalar type that is 1, 2, 4, or
! // 8 bytes, since that is what GCC built-in functions for atomic
// memory access expect.
template<typename _ITp>
struct __atomic_base
{
private:
! typedef _ITp __int_type;
! __int_type _M_i;
public:
__atomic_base() noexcept = default;
--- 346,362 ----
// atomic_char32_t char32_t
// atomic_wchar_t wchar_t
//
! // NB: Assuming _ITp is an integral scalar type that is 1, 2, 4, 8, or
! // 16 bytes, since that is what GCC built-in functions for atomic
// memory access expect.
template<typename _ITp>
struct __atomic_base
{
private:
! typedef _ITp __int_type;
! typedef _ITp __attribute__ ((atomic)) __atomic_int_type;
! __atomic_int_type _M_i;
public:
__atomic_base() noexcept = default;
*************** _GLIBCXX_BEGIN_NAMESPACE_VERSION
*** 669,677 ****
struct __atomic_base<_PTp*>
{
private:
! typedef _PTp* __pointer_type;
! __pointer_type _M_p;
// Factored out to facilitate explicit specialization.
constexpr ptrdiff_t
--- 670,679 ----
struct __atomic_base<_PTp*>
{
private:
! typedef _PTp* __pointer_type;
! typedef _PTp* __attribute ((atomic)) __atomic_pointer_type;
! __atomic_pointer_type _M_p;
// Factored out to facilitate explicit specialization.
constexpr ptrdiff_t
Index: libstdc++-v3/include/std/atomic
===================================================================
*** libstdc++-v3/include/std/atomic (revision 201248)
--- libstdc++-v3/include/std/atomic (working copy)
*************** _GLIBCXX_BEGIN_NAMESPACE_VERSION
*** 161,167 ****
struct atomic
{
private:
! _Tp _M_i;
public:
atomic() noexcept = default;
--- 161,167 ----
struct atomic
{
private:
! _Tp __attribute ((atomic)) _M_i;
public:
atomic() noexcept = default;
Index: gcc/testsuite/gcc.dg/atomic-exchange-1.c
===================================================================
*** gcc/testsuite/gcc.dg/atomic-exchange-1.c (revision 201248)
--- gcc/testsuite/gcc.dg/atomic-exchange-1.c (working copy)
***************
*** 7,13 ****
extern void abort(void);
! char v, count, ret;
main ()
{
--- 7,14 ----
extern void abort(void);
! char __attribute__ ((atomic)) v;
! char count, ret;
main ()
{
Index: gcc/testsuite/gcc.dg/atomic-exchange-2.c
===================================================================
*** gcc/testsuite/gcc.dg/atomic-exchange-2.c (revision 201248)
--- gcc/testsuite/gcc.dg/atomic-exchange-2.c (working copy)
***************
*** 7,13 ****
extern void abort(void);
! short v, count, ret;
main ()
{
--- 7,14 ----
extern void abort(void);
! short __attribute__ ((atomic)) v;
! short count, ret;
main ()
{
Index: gcc/testsuite/gcc.dg/atomic-exchange-3.c
===================================================================
*** gcc/testsuite/gcc.dg/atomic-exchange-3.c (revision 201248)
--- gcc/testsuite/gcc.dg/atomic-exchange-3.c (working copy)
***************
*** 7,13 ****
extern void abort(void);
! int v, count, ret;
main ()
{
--- 7,14 ----
extern void abort(void);
! int __attribute__ ((atomic)) v;
! int count, ret;
main ()
{
Index: gcc/testsuite/gcc.dg/atomic-exchange-4.c
===================================================================
*** gcc/testsuite/gcc.dg/atomic-exchange-4.c (revision 201248)
--- gcc/testsuite/gcc.dg/atomic-exchange-4.c (working copy)
***************
*** 9,15 ****
extern void abort(void);
! long long v, count, ret;
main ()
{
--- 9,16 ----
extern void abort(void);
! long long __attribute__ ((atomic)) v;
! long long count, ret;
main ()
{
Index: gcc/testsuite/gcc.dg/atomic-exchange-5.c
===================================================================
*** gcc/testsuite/gcc.dg/atomic-exchange-5.c (revision 201248)
--- gcc/testsuite/gcc.dg/atomic-exchange-5.c (working copy)
***************
*** 8,14 ****
extern void abort(void);
! __int128_t v, count, ret;
main ()
{
--- 8,15 ----
extern void abort(void);
! __int128_t __attribute__ ((atomic)) v;
! __int128_t count, ret;
main ()
{
Index: gcc/testsuite/gcc.dg/atomic-op-1.c
===================================================================
*** gcc/testsuite/gcc.dg/atomic-op-1.c (revision 201248)
--- gcc/testsuite/gcc.dg/atomic-op-1.c (working copy)
***************
*** 1,13 ****
/* Test __atomic routines for existence and proper execution on 1 byte
values with each valid memory model. */
/* { dg-do run } */
/* { dg-require-effective-target sync_char_short } */
/* Test the execution of the __atomic_*OP builtin routines for a char. */
extern void abort(void);
! char v, count, res;
const char init = ~0;
/* The fetch_op routines return the original value before the operation. */
--- 1,15 ----
/* Test __atomic routines for existence and proper execution on 1 byte
values with each valid memory model. */
/* { dg-do run } */
+ /* { dg-options "--std=c11" } */
/* { dg-require-effective-target sync_char_short } */
/* Test the execution of the __atomic_*OP builtin routines for a char. */
extern void abort(void);
! _Atomic char v;
! char count, res;
const char init = ~0;
/* The fetch_op routines return the original value before the operation. */
*************** test_or ()
*** 527,532 ****
--- 529,535 ----
abort ();
}
+ int
main ()
{
test_fetch_add ();
Index: gcc/testsuite/gcc.dg/atomic-op-2.c
===================================================================
*** gcc/testsuite/gcc.dg/atomic-op-2.c (revision 201248)
--- gcc/testsuite/gcc.dg/atomic-op-2.c (working copy)
***************
*** 1,6 ****
--- 1,7 ----
/* Test __atomic routines for existence and proper execution on 2 byte
values with each valid memory model. */
/* { dg-do run } */
+ /* { dg-options "--std=c11" } */
/* { dg-require-effective-target sync_char_short } */
***************
*** 8,14 ****
extern void abort(void);
! short v, count, res;
const short init = ~0;
/* The fetch_op routines return the original value before the operation. */
--- 9,16 ----
extern void abort(void);
! _Atomic short v;
! short count, res;
const short init = ~0;
/* The fetch_op routines return the original value before the operation. */
*************** test_or ()
*** 528,533 ****
--- 530,536 ----
abort ();
}
+ int
main ()
{
test_fetch_add ();
Index: gcc/testsuite/gcc.dg/atomic-op-3.c
===================================================================
*** gcc/testsuite/gcc.dg/atomic-op-3.c (revision 201248)
--- gcc/testsuite/gcc.dg/atomic-op-3.c (working copy)
***************
*** 1,13 ****
/* Test __atomic routines for existence and proper execution on 4 byte
values with each valid memory model. */
/* { dg-do run } */
/* { dg-require-effective-target sync_int_long } */
/* Test the execution of the __atomic_*OP builtin routines for an int. */
extern void abort(void);
! int v, count, res;
const int init = ~0;
/* The fetch_op routines return the original value before the operation. */
--- 1,15 ----
/* Test __atomic routines for existence and proper execution on 4 byte
values with each valid memory model. */
/* { dg-do run } */
+ /* { dg-options "--std=c11" } */
/* { dg-require-effective-target sync_int_long } */
/* Test the execution of the __atomic_*OP builtin routines for an int. */
extern void abort(void);
! _Atomic int v;
! int count, res;
const int init = ~0;
/* The fetch_op routines return the original value before the operation. */
*************** test_or ()
*** 527,532 ****
--- 529,535 ----
abort ();
}
+ int
main ()
{
test_fetch_add ();
Index: gcc/testsuite/gcc.dg/atomic-op-4.c
===================================================================
*** gcc/testsuite/gcc.dg/atomic-op-4.c (revision 201248)
--- gcc/testsuite/gcc.dg/atomic-op-4.c (working copy)
***************
*** 2,15 ****
values with each valid memory model. */
/* { dg-do run } */
/* { dg-require-effective-target sync_long_long_runtime } */
! /* { dg-options "" } */
! /* { dg-options "-march=pentium" { target { { i?86-*-* x86_64-*-* } && ia32 } } } */
/* Test the execution of the __atomic_*OP builtin routines for long long. */
extern void abort(void);
! long long v, count, res;
const long long init = ~0;
/* The fetch_op routines return the original value before the operation. */
--- 2,16 ----
values with each valid memory model. */
/* { dg-do run } */
/* { dg-require-effective-target sync_long_long_runtime } */
! /* { dg-options "--std=c11" } */
! /* { dg-options "--std=c11 -march=pentium" { target { { i?86-*-* x86_64-*-* } && ia32 } } } */
/* Test the execution of the __atomic_*OP builtin routines for long long. */
extern void abort(void);
! _Atomic long long v;
! long long count, res;
const long long init = ~0;
/* The fetch_op routines return the original value before the operation. */
*************** test_or ()
*** 529,534 ****
--- 530,536 ----
abort ();
}
+ int
main ()
{
test_fetch_add ();
Index: gcc/testsuite/gcc.dg/atomic-op-5.c
===================================================================
*** gcc/testsuite/gcc.dg/atomic-op-5.c (revision 201248)
--- gcc/testsuite/gcc.dg/atomic-op-5.c (working copy)
***************
*** 1,14 ****
/* Test __atomic routines for existence and proper execution on 16 byte
values with each valid memory model. */
/* { dg-do run } */
/* { dg-require-effective-target sync_int_128_runtime } */
! /* { dg-options "-mcx16" { target { i?86-*-* x86_64-*-* } } } */
/* Test the execution of the __atomic_*OP builtin routines for an int_128. */
extern void abort(void);
! __int128_t v, count, res;
const __int128_t init = ~0;
/* The fetch_op routines return the original value before the operation. */
--- 1,16 ----
/* Test __atomic routines for existence and proper execution on 16 byte
values with each valid memory model. */
/* { dg-do run } */
+ /* { dg-options "--std=c11" } */
/* { dg-require-effective-target sync_int_128_runtime } */
! /* { dg-options "--std=c11 -mcx16" { target { i?86-*-* x86_64-*-* } } } */
/* Test the execution of the __atomic_*OP builtin routines for an int_128. */
extern void abort(void);
! _Atomic __int128_t v;
! __int128_t count, res;
const __int128_t init = ~0;
/* The fetch_op routines return the original value before the operation. */
*************** test_or ()
*** 528,533 ****
--- 530,536 ----
abort ();
}
+ int
main ()
{
test_fetch_add ();
next prev parent reply other threads:[~2013-07-30 17:14 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-26 17:18 [PATCH] Add atomic type qualifier Andrew MacLeod
2013-07-26 19:24 ` Andi Kleen
2013-07-26 19:34 ` Andrew MacLeod
2013-07-26 21:14 ` Andi Kleen
2013-07-26 22:29 ` Andrew MacLeod
2013-07-26 20:42 ` Hans-Peter Nilsson
2013-07-26 23:58 ` Joseph S. Myers
2013-07-27 1:15 ` Andrew MacLeod
2013-08-01 21:54 ` Andrew MacLeod
2013-07-28 21:15 ` Joseph S. Myers
2013-07-29 15:47 ` Andrew MacLeod
2013-07-29 16:12 ` Joseph S. Myers
2013-07-29 16:30 ` Andrew MacLeod
2013-07-29 16:48 ` Joseph S. Myers
2013-07-29 18:20 ` Andrew MacLeod
2013-07-29 23:24 ` Andrew MacLeod
2013-07-30 12:03 ` Joseph S. Myers
2013-07-30 12:38 ` Andrew MacLeod
2013-07-30 13:25 ` Joseph S. Myers
2013-07-30 13:58 ` Andrew MacLeod
2013-07-31 12:19 ` Andrew MacLeod
2013-07-29 16:24 ` Andrew MacLeod
2013-07-30 16:56 ` [PATCH 0/5] Atomic " Andrew MacLeod
2013-07-30 17:13 ` [PATCH 2/5] Atomic type qualifier - Add atomic type to tree node Andrew MacLeod
2013-07-30 17:14 ` [PATCH 1/5] Atomic type qualifier - Add type alignment override hook Andrew MacLeod
2013-07-30 17:14 ` [PATCH 4/5] Atomic type qualifier - Change built-in function types Andrew MacLeod
2013-07-30 17:14 ` [PATCH 3/5] Atomic type qualifier - front end changes Andrew MacLeod
2013-08-09 0:06 ` Joseph S. Myers
2013-07-30 17:32 ` Andrew MacLeod [this message]
2013-08-02 19:22 ` [PATCH] - C11 expressions and stdatomic.h - Just for current state Andrew MacLeod
2013-08-07 23:06 ` Joseph S. Myers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=51F7F45D.9030400@redhat.com \
--to=amacleod@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).