[v2,1/2] testsuite: Add dg-require-atomic-cmpxchg-word

Message ID 20231004170455.76C1A2043D@pchp3.se.axis.com
State Accepted
Headers
Series [v2,1/2] testsuite: Add dg-require-atomic-cmpxchg-word |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Hans-Peter Nilsson Oct. 4, 2023, 5:04 p.m. UTC
  > From: Hans-Peter Nilsson <hp@axis.com>
> Date: Wed, 4 Oct 2023 17:15:28 +0200

> New version coming up.

Using pointer-sized int instead of int,
__atomic_compare_exchange instead of __atomic_exchange,
renamed to atomic-cmpxchg-word from atomic-exchange, and
updating a comment that already seemed reasonably well
placed.

Tested as with v1 1/2.

Ok to commit?

-- >8 --
Some targets (armv6-m) support inline atomic load and store,
i.e. dg-require-thread-fence matches, but not atomic operations like
compare and exchange.

This directive can be used to replace uses of dg-require-thread-fence
where an atomic operation is actually used.

	* testsuite/lib/dg-options.exp (dg-require-atomic-cmpxchg-word):
	New proc.
	* testsuite/lib/libstdc++.exp (check_v3_target_atomic_cmpxchg_word):
	Ditto.
---
 libstdc++-v3/testsuite/lib/dg-options.exp |  9 ++++++
 libstdc++-v3/testsuite/lib/libstdc++.exp  | 37 +++++++++++++++++++++++
 2 files changed, 46 insertions(+)
  

Comments

Hans-Peter Nilsson Oct. 12, 2023, 2:21 a.m. UTC | #1
Ping.

> From: Hans-Peter Nilsson <hp@axis.com>
> Date: Wed, 4 Oct 2023 19:04:55 +0200
> 
> > From: Hans-Peter Nilsson <hp@axis.com>
> > Date: Wed, 4 Oct 2023 17:15:28 +0200
> 
> > New version coming up.
> 
> Using pointer-sized int instead of int,
> __atomic_compare_exchange instead of __atomic_exchange,
> renamed to atomic-cmpxchg-word from atomic-exchange, and
> updating a comment that already seemed reasonably well
> placed.
> 
> Tested as with v1 1/2.
> 
> Ok to commit?
> 
> -- >8 --
> Some targets (armv6-m) support inline atomic load and store,
> i.e. dg-require-thread-fence matches, but not atomic operations like
> compare and exchange.
> 
> This directive can be used to replace uses of dg-require-thread-fence
> where an atomic operation is actually used.
> 
> 	* testsuite/lib/dg-options.exp (dg-require-atomic-cmpxchg-word):
> 	New proc.
> 	* testsuite/lib/libstdc++.exp (check_v3_target_atomic_cmpxchg_word):
> 	Ditto.
> ---
>  libstdc++-v3/testsuite/lib/dg-options.exp |  9 ++++++
>  libstdc++-v3/testsuite/lib/libstdc++.exp  | 37 +++++++++++++++++++++++
>  2 files changed, 46 insertions(+)
> 
> diff --git a/libstdc++-v3/testsuite/lib/dg-options.exp b/libstdc++-v3/testsuite/lib/dg-options.exp
> index 84ad0c65330b..850442b6b7c1 100644
> --- a/libstdc++-v3/testsuite/lib/dg-options.exp
> +++ b/libstdc++-v3/testsuite/lib/dg-options.exp
> @@ -133,6 +133,15 @@ proc dg-require-thread-fence { args } {
>      return
>  }
>  
> +proc dg-require-atomic-cmpxchg-word { args } {
> +    if { ![ check_v3_target_atomic_cmpxchg_word ] } {
> +	upvar dg-do-what dg-do-what
> +	set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
> +	return
> +    }
> +    return
> +}
> +
>  proc dg-require-atomic-builtins { args } {
>      if { ![ check_v3_target_atomic_builtins ] } {
>  	upvar dg-do-what dg-do-what
> diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp b/libstdc++-v3/testsuite/lib/libstdc++.exp
> index 608056e5068e..4bedb36dc6f9 100644
> --- a/libstdc++-v3/testsuite/lib/libstdc++.exp
> +++ b/libstdc++-v3/testsuite/lib/libstdc++.exp
> @@ -1221,6 +1221,43 @@ proc check_v3_target_thread_fence { } {
>      }]
>  }
>  
> +proc check_v3_target_atomic_cmpxchg_word { } {
> +    return [check_v3_target_prop_cached et_atomic_cmpxchg_word {
> +	global cxxflags
> +	global DEFAULT_CXXFLAGS
> +
> +	# Set up and link a C++11 test program that depends on
> +	# atomic-compare-exchange being available for a pointer-sized
> +	# integer.  It should be sufficient as gcc can derive all
> +	# other operations when a target implements this operation.
> +	set src atomic_cmpxchg_word[pid].cc
> +
> +	set f [open $src "w"]
> +	puts $f "
> +	__UINTPTR_TYPE__ i, j, k;
> +	int main() {
> +	__atomic_compare_exchange (&i, &j, &k, 1, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
> +	return 0;
> +	}"
> +	close $f
> +
> +	set cxxflags_saved $cxxflags
> +	set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror -std=gnu++11"
> +
> +	set lines [v3_target_compile $src /dev/null executable ""]
> +	set cxxflags $cxxflags_saved
> +	file delete $src
> +
> +	if [string match "" $lines] {
> +	    # No error message, linking succeeded.
> +	    return 1
> +	} else {
> +	    verbose "check_v3_target_atomic_cmpxchg_word: compilation failed" 2
> +	    return 0
> +	}
> +    }]
> +}
> +
>  # Return 1 if atomics_bool and atomic_int are always lock-free, 0 otherwise.
>  proc check_v3_target_atomic_builtins { } {
>      return [check_v3_target_prop_cached et_atomic_builtins {
> -- 
> 2.30.2
>
  
Christophe Lyon Oct. 12, 2023, 2:38 p.m. UTC | #2
LGTM but I'm not a maintainer ;-)

On Thu, 12 Oct 2023 at 04:21, Hans-Peter Nilsson <hp@axis.com> wrote:
>
> Ping.
>
> > From: Hans-Peter Nilsson <hp@axis.com>
> > Date: Wed, 4 Oct 2023 19:04:55 +0200
> >
> > > From: Hans-Peter Nilsson <hp@axis.com>
> > > Date: Wed, 4 Oct 2023 17:15:28 +0200
> >
> > > New version coming up.
> >
> > Using pointer-sized int instead of int,
> > __atomic_compare_exchange instead of __atomic_exchange,
> > renamed to atomic-cmpxchg-word from atomic-exchange, and
> > updating a comment that already seemed reasonably well
> > placed.
> >
> > Tested as with v1 1/2.
> >
> > Ok to commit?
> >
> > -- >8 --
> > Some targets (armv6-m) support inline atomic load and store,
> > i.e. dg-require-thread-fence matches, but not atomic operations like
> > compare and exchange.
> >
> > This directive can be used to replace uses of dg-require-thread-fence
> > where an atomic operation is actually used.
> >
> >       * testsuite/lib/dg-options.exp (dg-require-atomic-cmpxchg-word):
> >       New proc.
> >       * testsuite/lib/libstdc++.exp (check_v3_target_atomic_cmpxchg_word):
> >       Ditto.
> > ---
> >  libstdc++-v3/testsuite/lib/dg-options.exp |  9 ++++++
> >  libstdc++-v3/testsuite/lib/libstdc++.exp  | 37 +++++++++++++++++++++++
> >  2 files changed, 46 insertions(+)
> >
> > diff --git a/libstdc++-v3/testsuite/lib/dg-options.exp b/libstdc++-v3/testsuite/lib/dg-options.exp
> > index 84ad0c65330b..850442b6b7c1 100644
> > --- a/libstdc++-v3/testsuite/lib/dg-options.exp
> > +++ b/libstdc++-v3/testsuite/lib/dg-options.exp
> > @@ -133,6 +133,15 @@ proc dg-require-thread-fence { args } {
> >      return
> >  }
> >
> > +proc dg-require-atomic-cmpxchg-word { args } {
> > +    if { ![ check_v3_target_atomic_cmpxchg_word ] } {
> > +     upvar dg-do-what dg-do-what
> > +     set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
> > +     return
> > +    }
> > +    return
> > +}
> > +
> >  proc dg-require-atomic-builtins { args } {
> >      if { ![ check_v3_target_atomic_builtins ] } {
> >       upvar dg-do-what dg-do-what
> > diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp b/libstdc++-v3/testsuite/lib/libstdc++.exp
> > index 608056e5068e..4bedb36dc6f9 100644
> > --- a/libstdc++-v3/testsuite/lib/libstdc++.exp
> > +++ b/libstdc++-v3/testsuite/lib/libstdc++.exp
> > @@ -1221,6 +1221,43 @@ proc check_v3_target_thread_fence { } {
> >      }]
> >  }
> >
> > +proc check_v3_target_atomic_cmpxchg_word { } {
> > +    return [check_v3_target_prop_cached et_atomic_cmpxchg_word {
> > +     global cxxflags
> > +     global DEFAULT_CXXFLAGS
> > +
> > +     # Set up and link a C++11 test program that depends on
> > +     # atomic-compare-exchange being available for a pointer-sized
> > +     # integer.  It should be sufficient as gcc can derive all
> > +     # other operations when a target implements this operation.
> > +     set src atomic_cmpxchg_word[pid].cc
> > +
> > +     set f [open $src "w"]
> > +     puts $f "
> > +     __UINTPTR_TYPE__ i, j, k;
> > +     int main() {
> > +     __atomic_compare_exchange (&i, &j, &k, 1, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
> > +     return 0;
> > +     }"
> > +     close $f
> > +
> > +     set cxxflags_saved $cxxflags
> > +     set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror -std=gnu++11"
> > +
> > +     set lines [v3_target_compile $src /dev/null executable ""]
> > +     set cxxflags $cxxflags_saved
> > +     file delete $src
> > +
> > +     if [string match "" $lines] {
> > +         # No error message, linking succeeded.
> > +         return 1
> > +     } else {
> > +         verbose "check_v3_target_atomic_cmpxchg_word: compilation failed" 2
> > +         return 0
> > +     }
> > +    }]
> > +}
> > +
> >  # Return 1 if atomics_bool and atomic_int are always lock-free, 0 otherwise.
> >  proc check_v3_target_atomic_builtins { } {
> >      return [check_v3_target_prop_cached et_atomic_builtins {
> > --
> > 2.30.2
> >
  
Jeff Law Oct. 12, 2023, 4:10 p.m. UTC | #3
On 10/12/23 08:38, Christophe Lyon wrote:
> LGTM but I'm not a maintainer ;-)
LGTM to as well -- I usually try to stay out of libstdc++, but this 
looks simple enough.  Both patches in this series are OK.

jeff
  
Jonathan Wakely Oct. 12, 2023, 10:23 p.m. UTC | #4
On Thu, 12 Oct 2023, 17:11 Jeff Law, <jeffreyalaw@gmail.com> wrote:

>
>
> On 10/12/23 08:38, Christophe Lyon wrote:
> > LGTM but I'm not a maintainer ;-)
> LGTM to as well -- I usually try to stay out of libstdc++, but this
> looks simple enough.  Both patches in this series are OK.
>

Thanks for stepping in, Jeff. The patches are indeed fine, I'm just offline
due to circumstances beyond my control. I hope normal service will resume
soon.
  
Torbjorn SVENSSON Feb. 7, 2024, 4:31 p.m. UTC | #5
Hi,

Is it okay to backport 62b29347c38394ae32858f2301aa9aa65205984e, 
2a4d9e4f533c77870cc0eb60fbbd8047da4c7386 and 
ba0cde8ba2d93b7193050eb5ef3cc6f7a2cdfe61 to releases/gcc-13?

Without this backport, I see these failures on arm-none-eabi:

FAIL: 29_atomics/atomic/compare_exchange_padding.cc (test for excess errors)
FAIL: 29_atomics/atomic_ref/compare_exchange_padding.cc (test for excess 
errors)

Kind regards,
Torbjörn

On 2023-10-13 00:23, Jonathan Wakely wrote:
> 
> 
> On Thu, 12 Oct 2023, 17:11 Jeff Law, <jeffreyalaw@gmail.com 
> <mailto:jeffreyalaw@gmail.com>> wrote:
> 
> 
> 
>     On 10/12/23 08:38, Christophe Lyon wrote:
>      > LGTM but I'm not a maintainer ;-)
>     LGTM to as well -- I usually try to stay out of libstdc++, but this
>     looks simple enough.  Both patches in this series are OK.
> 
> 
> Thanks for stepping in, Jeff. The patches are indeed fine, I'm just 
> offline due to circumstances beyond my control. I hope normal service 
> will resume soon.
> 
>
  
Jonathan Wakely Feb. 7, 2024, 4:33 p.m. UTC | #6
On Wed, 7 Feb 2024 at 16:31, Torbjorn SVENSSON <
torbjorn.svensson@foss.st.com> wrote:

> Hi,
>
> Is it okay to backport 62b29347c38394ae32858f2301aa9aa65205984e,
> 2a4d9e4f533c77870cc0eb60fbbd8047da4c7386 and
> ba0cde8ba2d93b7193050eb5ef3cc6f7a2cdfe61 to releases/gcc-13?
>
> Without this backport, I see these failures on arm-none-eabi:
>
> FAIL: 29_atomics/atomic/compare_exchange_padding.cc (test for excess
> errors)
> FAIL: 29_atomics/atomic_ref/compare_exchange_padding.cc (test for excess
> errors)
>

Yes, OK


>
> Kind regards,
> Torbjörn
>
> On 2023-10-13 00:23, Jonathan Wakely wrote:
> >
> >
> > On Thu, 12 Oct 2023, 17:11 Jeff Law, <jeffreyalaw@gmail.com
> > <mailto:jeffreyalaw@gmail.com>> wrote:
> >
> >
> >
> >     On 10/12/23 08:38, Christophe Lyon wrote:
> >      > LGTM but I'm not a maintainer ;-)
> >     LGTM to as well -- I usually try to stay out of libstdc++, but this
> >     looks simple enough.  Both patches in this series are OK.
> >
> >
> > Thanks for stepping in, Jeff. The patches are indeed fine, I'm just
> > offline due to circumstances beyond my control. I hope normal service
> > will resume soon.
> >
> >
>
>
  
Torbjorn SVENSSON Feb. 7, 2024, 5:37 p.m. UTC | #7
On 2024-02-07 17:33, Jonathan Wakely wrote:
> 
> 
> On Wed, 7 Feb 2024 at 16:31, Torbjorn SVENSSON 
> <torbjorn.svensson@foss.st.com <mailto:torbjorn.svensson@foss.st.com>> 
> wrote:
> 
>     Hi,
> 
>     Is it okay to backport 62b29347c38394ae32858f2301aa9aa65205984e,
>     2a4d9e4f533c77870cc0eb60fbbd8047da4c7386 and
>     ba0cde8ba2d93b7193050eb5ef3cc6f7a2cdfe61 to releases/gcc-13?
> 
>     Without this backport, I see these failures on arm-none-eabi:
> 
>     FAIL: 29_atomics/atomic/compare_exchange_padding.cc (test for excess
>     errors)
>     FAIL: 29_atomics/atomic_ref/compare_exchange_padding.cc (test for
>     excess
>     errors)
> 
> 
> Yes, OK

Pushed as b937b1189069b24f8d1a5c25d8f062029784fb0c, 
fa0e0c28ee8f6ca2f8d5c50737647bef734dc898 and 
18fd8d29b27ec9ace70098b4a451f5296276812e.
  

Patch

diff --git a/libstdc++-v3/testsuite/lib/dg-options.exp b/libstdc++-v3/testsuite/lib/dg-options.exp
index 84ad0c65330b..850442b6b7c1 100644
--- a/libstdc++-v3/testsuite/lib/dg-options.exp
+++ b/libstdc++-v3/testsuite/lib/dg-options.exp
@@ -133,6 +133,15 @@  proc dg-require-thread-fence { args } {
     return
 }
 
+proc dg-require-atomic-cmpxchg-word { args } {
+    if { ![ check_v3_target_atomic_cmpxchg_word ] } {
+	upvar dg-do-what dg-do-what
+	set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
+	return
+    }
+    return
+}
+
 proc dg-require-atomic-builtins { args } {
     if { ![ check_v3_target_atomic_builtins ] } {
 	upvar dg-do-what dg-do-what
diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp b/libstdc++-v3/testsuite/lib/libstdc++.exp
index 608056e5068e..4bedb36dc6f9 100644
--- a/libstdc++-v3/testsuite/lib/libstdc++.exp
+++ b/libstdc++-v3/testsuite/lib/libstdc++.exp
@@ -1221,6 +1221,43 @@  proc check_v3_target_thread_fence { } {
     }]
 }
 
+proc check_v3_target_atomic_cmpxchg_word { } {
+    return [check_v3_target_prop_cached et_atomic_cmpxchg_word {
+	global cxxflags
+	global DEFAULT_CXXFLAGS
+
+	# Set up and link a C++11 test program that depends on
+	# atomic-compare-exchange being available for a pointer-sized
+	# integer.  It should be sufficient as gcc can derive all
+	# other operations when a target implements this operation.
+	set src atomic_cmpxchg_word[pid].cc
+
+	set f [open $src "w"]
+	puts $f "
+	__UINTPTR_TYPE__ i, j, k;
+	int main() {
+	__atomic_compare_exchange (&i, &j, &k, 1, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
+	return 0;
+	}"
+	close $f
+
+	set cxxflags_saved $cxxflags
+	set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror -std=gnu++11"
+
+	set lines [v3_target_compile $src /dev/null executable ""]
+	set cxxflags $cxxflags_saved
+	file delete $src
+
+	if [string match "" $lines] {
+	    # No error message, linking succeeded.
+	    return 1
+	} else {
+	    verbose "check_v3_target_atomic_cmpxchg_word: compilation failed" 2
+	    return 0
+	}
+    }]
+}
+
 # Return 1 if atomics_bool and atomic_int are always lock-free, 0 otherwise.
 proc check_v3_target_atomic_builtins { } {
     return [check_v3_target_prop_cached et_atomic_builtins {