public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][testsuite] Add gcc.dg/ia64-sync-5.c
@ 2020-08-06 12:23 Tom de Vries
  2020-08-06 23:55 ` Mike Stump
  2020-08-11 18:53 ` [PR96519] " Kwok Cheung Yeung
  0 siblings, 2 replies; 4+ messages in thread
From: Tom de Vries @ 2020-08-06 12:23 UTC (permalink / raw)
  To: gcc-patches

Hi,

There currently is no sync_char_short-enabled run test that tests
__sync_val_compare_and_swap.

Fix this by copying ia64-sync-3.c and modifying it for char/short.

Tested on x86_64.

OK for trunk?

Thanks,
- Tom

[testsuite] Add gcc.dg/ia64-sync-5.c

2020-08-06  Kwok Cheung Yeung  <kcy@codesourcery.com>
	    Tom de Vries  <tdevries@suse.de>

gcc/testsuite/ChangeLog:

	* gcc.dg/ia64-sync-5.c: New test.

---
 gcc/testsuite/gcc.dg/ia64-sync-5.c | 83 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 83 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/ia64-sync-5.c b/gcc/testsuite/gcc.dg/ia64-sync-5.c
new file mode 100644
index 00000000000..8b16b29b20e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ia64-sync-5.c
@@ -0,0 +1,83 @@
+/* { dg-do run } */
+/* { dg-require-effective-target sync_char_short } */
+/* { dg-options } */
+/* { dg-options "-march=i486" { target { { i?86-*-* x86_64-*-* } && ia32 } } } */
+/* { dg-options "-mcpu=v9" { target sparc*-*-* } } */
+
+/* Test basic functionality of the intrinsics.  */
+
+/* This is a copy of gcc.dg/ia64-sync-3.c, for 8-bit and 16-bit.  */
+
+__extension__ typedef __SIZE_TYPE__ size_t;
+
+extern void abort (void);
+extern void *memcpy (void *, const void *, size_t);
+extern int memcmp (const void *, const void *, size_t);
+
+static char AC[4];
+static char init_qi[4] = { -30,-30,-50,-50 };
+static char test_qi[4] = { -115,-115,25,25 };
+
+static void
+do_qi (void)
+{
+  if (__sync_val_compare_and_swap(AC+0, -30, -115) != -30)
+    abort ();
+  if (__sync_val_compare_and_swap(AC+0, -30, -115) != -115)
+    abort ();
+  if (__sync_bool_compare_and_swap(AC+1, -30, -115) != 1)
+    abort ();
+  if (__sync_bool_compare_and_swap(AC+1, -30, -115) != 0)
+    abort ();
+
+  if (__sync_val_compare_and_swap(AC+2, AC[2], 25) != -50)
+    abort ();
+  if (__sync_val_compare_and_swap(AC+2, AC[2], 25) != 25)
+    abort ();
+  if (__sync_bool_compare_and_swap(AC+3, AC[3], 25) != 1)
+    abort ();
+  if (__sync_bool_compare_and_swap(AC+3, AC[3], 25) != 1)
+    abort ();
+}
+
+static short AS[4];
+static short init_hi[4] = { -30,-30,-50,-50 };
+static short test_hi[4] = { -115,-115,25,25 };
+
+static void
+do_hi (void)
+{
+  if (__sync_val_compare_and_swap(AS+0, -30, -115) != -30)
+    abort ();
+  if (__sync_val_compare_and_swap(AS+0, -30, -115) != -115)
+    abort ();
+  if (__sync_bool_compare_and_swap(AS+1, -30, -115) != 1)
+    abort ();
+  if (__sync_bool_compare_and_swap(AS+1, -30, -115) != 0)
+    abort ();
+
+  if (__sync_val_compare_and_swap(AS+2, AS[2], 25) != -50)
+    abort ();
+  if (__sync_val_compare_and_swap(AS+2, AS[2], 25) != 25)
+    abort ();
+  if (__sync_bool_compare_and_swap(AS+3, AS[3], 25) != 1)
+    abort ();
+  if (__sync_bool_compare_and_swap(AS+3, AS[3], 25) != 1)
+    abort ();
+}
+
+int main()
+{
+  memcpy(AC, init_qi, sizeof(init_qi));
+  memcpy(AS, init_hi, sizeof(init_hi));
+
+  do_qi ();
+  do_hi ();
+
+  if (memcmp (AC, test_qi, sizeof(test_qi)))
+    abort ();
+  if (memcmp (AS, test_hi, sizeof(test_hi)))
+    abort ();
+
+  return 0;
+}

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH][testsuite] Add gcc.dg/ia64-sync-5.c
  2020-08-06 12:23 [PATCH][testsuite] Add gcc.dg/ia64-sync-5.c Tom de Vries
@ 2020-08-06 23:55 ` Mike Stump
  2020-08-11 18:53 ` [PR96519] " Kwok Cheung Yeung
  1 sibling, 0 replies; 4+ messages in thread
From: Mike Stump @ 2020-08-06 23:55 UTC (permalink / raw)
  To: Tom de Vries; +Cc: gcc-patches

On Aug 6, 2020, at 5:23 AM, Tom de Vries <tdevries@suse.de> wrote:
> 
> There currently is no sync_char_short-enabled run test that tests
> __sync_val_compare_and_swap.
> 
> OK for trunk?

Ok.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PR96519] Re: [PATCH][testsuite] Add gcc.dg/ia64-sync-5.c
  2020-08-06 12:23 [PATCH][testsuite] Add gcc.dg/ia64-sync-5.c Tom de Vries
  2020-08-06 23:55 ` Mike Stump
@ 2020-08-11 18:53 ` Kwok Cheung Yeung
  2020-08-12  8:50   ` Richard Sandiford
  1 sibling, 1 reply; 4+ messages in thread
From: Kwok Cheung Yeung @ 2020-08-11 18:53 UTC (permalink / raw)
  To: Tom de Vries, gcc-patches, mikestump; +Cc: seurer, clyon

[-- Attachment #1: Type: text/plain, Size: 776 bytes --]

Hello

On 06/08/2020 1:23 pm, Tom de Vries wrote:
 > +static char AC[4];
 > +static char init_qi[4] = { -30,-30,-50,-50 };
 > +static char test_qi[4] = { -115,-115,25,25 };
 > +
 > +static void
 > +do_qi (void)
 > +{
 > +  if (__sync_val_compare_and_swap(AC+0, -30, -115) != -30)
 > +    abort ();

If 'char' is unsigned by default, then init_qi will contain { 226, 226, 206, 
206} and test_qi { 141, 141, 25, 25 }, which will result in the comparison 
against -30 failing when the previous value of AC[0] is implicitly promoted to 
signed int. This can be fixed by making the array element types explicitly signed.

This issue is tracked as issue 96519 on the tracker. I have checked that the 
test now passes on PowerPC and Aarch64. Is the fix okay for trunk?

Thanks

Kwok

[-- Attachment #2: ia64-sync-5_fix.patch --]
[-- Type: text/plain, Size: 1293 bytes --]

commit fc6ac3af45a238da0bd65e020ae6f0f165b57b87
Author: Kwok Cheung Yeung <kcy@codesourcery.com>
Date:   Tue Aug 11 09:41:10 2020 -0700

    Fix gcc.dg/ia64-sync-5.c for architectures with unsigned char as default (PR 96519)
    
    If char is unsigned, then comparisons of the char array elements against
    negative integers in the test will fail as values in the array will always
    be positive, and will remain so when promoted to signed int.
    
    2020-08-11  Kwok Cheung Yeung  <kcy@codesourcery.com>
    
    	PR testsuite/96519
    
    	gcc/testsuite/
    	* gcc.dg/ia64-sync-5.c (AC, init_qi, test_qi): Change element type to
    	signed char.

diff --git a/gcc/testsuite/gcc.dg/ia64-sync-5.c b/gcc/testsuite/gcc.dg/ia64-sync-5.c
index 8b16b29..a3923b0 100644
--- a/gcc/testsuite/gcc.dg/ia64-sync-5.c
+++ b/gcc/testsuite/gcc.dg/ia64-sync-5.c
@@ -14,9 +14,9 @@ extern void abort (void);
 extern void *memcpy (void *, const void *, size_t);
 extern int memcmp (const void *, const void *, size_t);
 
-static char AC[4];
-static char init_qi[4] = { -30,-30,-50,-50 };
-static char test_qi[4] = { -115,-115,25,25 };
+static signed char AC[4];
+static signed char init_qi[4] = { -30,-30,-50,-50 };
+static signed char test_qi[4] = { -115,-115,25,25 };
 
 static void
 do_qi (void)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PR96519] Re: [PATCH][testsuite] Add gcc.dg/ia64-sync-5.c
  2020-08-11 18:53 ` [PR96519] " Kwok Cheung Yeung
@ 2020-08-12  8:50   ` Richard Sandiford
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Sandiford @ 2020-08-12  8:50 UTC (permalink / raw)
  To: Kwok Cheung Yeung; +Cc: Tom de Vries, gcc-patches, mikestump, seurer, clyon

Kwok Cheung Yeung <kcy@codesourcery.com> writes:
> Hello
>
> On 06/08/2020 1:23 pm, Tom de Vries wrote:
>  > +static char AC[4];
>  > +static char init_qi[4] = { -30,-30,-50,-50 };
>  > +static char test_qi[4] = { -115,-115,25,25 };
>  > +
>  > +static void
>  > +do_qi (void)
>  > +{
>  > +  if (__sync_val_compare_and_swap(AC+0, -30, -115) != -30)
>  > +    abort ();
>
> If 'char' is unsigned by default, then init_qi will contain { 226, 226, 206, 
> 206} and test_qi { 141, 141, 25, 25 }, which will result in the comparison 
> against -30 failing when the previous value of AC[0] is implicitly promoted to 
> signed int. This can be fixed by making the array element types explicitly signed.
>
> This issue is tracked as issue 96519 on the tracker. I have checked that the 
> test now passes on PowerPC and Aarch64. Is the fix okay for trunk?
>
> Thanks
>
> Kwok
>
> commit fc6ac3af45a238da0bd65e020ae6f0f165b57b87
> Author: Kwok Cheung Yeung <kcy@codesourcery.com>
> Date:   Tue Aug 11 09:41:10 2020 -0700
>
>     Fix gcc.dg/ia64-sync-5.c for architectures with unsigned char as default (PR 96519)
>     
>     If char is unsigned, then comparisons of the char array elements against
>     negative integers in the test will fail as values in the array will always
>     be positive, and will remain so when promoted to signed int.
>     
>     2020-08-11  Kwok Cheung Yeung  <kcy@codesourcery.com>
>     
>     	PR testsuite/96519
>     
>     	gcc/testsuite/
>     	* gcc.dg/ia64-sync-5.c (AC, init_qi, test_qi): Change element type to
>     	signed char.

OK, thanks.

Richard

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-08-12  8:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-06 12:23 [PATCH][testsuite] Add gcc.dg/ia64-sync-5.c Tom de Vries
2020-08-06 23:55 ` Mike Stump
2020-08-11 18:53 ` [PR96519] " Kwok Cheung Yeung
2020-08-12  8:50   ` Richard Sandiford

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).