This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 5/5] Atomic type qualifier - Use atomic objects


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.


	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 ();

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]