public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Thomas Schwinge <thomas@codesourcery.com>
Cc: gcc-patches@gcc.gnu.org, Tobias Burnus <tobias@codesourcery.com>,
	Marcel Vollweiler <marcel@codesourcery.com>
Subject: Re: [committed] openmp: Conforming device numbers and omp_{initial,invalid}_device
Date: Wed, 15 Jun 2022 10:46:30 +0200	[thread overview]
Message-ID: <YqmcZiX9pJDYPRb0@tucnak> (raw)
In-Reply-To: <87r13ri4e6.fsf@dem-tschwing-1.ger.mentorg.com>

On Tue, Jun 14, 2022 at 06:41:37PM +0200, Thomas Schwinge wrote:
> Hi Jakub!
> 
> On 2022-06-13T14:06:39+0200, Jakub Jelinek via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
> > OpenMP 5.2 changed once more what device numbers are allowed.
> 
> > libgomp/
> 
> >       * testsuite/libgomp.c-c++-common/target-is-accessible-1.c (main): Add
> >       test with omp_initial_device.  Use -5 instead of -1 for negative value
> >       test.
> >       * testsuite/libgomp.fortran/target-is-accessible-1.f90 (main):
> >       Likewise.  Reorder stop numbers.
> 
> In an offloading configuration, I'm seeing:
> 
>     PASS: libgomp.fortran/get-mapped-ptr-1.f90   -O  (test for excess errors)
>     [-PASS:-]{+FAIL:+} libgomp.fortran/get-mapped-ptr-1.f90   -O  execution test
> 
> Does that one need similar treatment?

I assume not just that but libgomp.c-c++-common/get-mapped-ptr-1.c too?

It both needs the same treatment, and in the get-mapped-ptr-1.c
case there is even UB, while the Fortran version was using c_loc (q)
as the host pointer, in C/C++ it was using q which was value of
uninitialized pointer.

Tested on x86_64-linux, committed to trunk.

2022-06-15  Jakub Jelinek  <jakub@redhat.com>

	* testsuite/libgomp.c-c++-common/get-mapped-ptr-1.c (main): Initialize
	q to ddress of an automatic variable.  Use -5 instead of -1 in
	omp_get_mapped_ptr call.  Add test with omp_initial_device.
	* testsuite/libgomp.fortran/get-mapped-ptr-1.f90 (main): Use -5 instead
	of -1 in omp_get_mapped_ptr call.  Add test with omp_initial_device.
	Renumber stop arguments afterwards.

--- libgomp/testsuite/libgomp.c-c++-common/get-mapped-ptr-1.c.jj	2022-05-09 09:09:20.963464303 +0200
+++ libgomp/testsuite/libgomp.c-c++-common/get-mapped-ptr-1.c	2022-06-15 09:39:17.518746512 +0200
@@ -6,7 +6,10 @@ main ()
 {
   int d = omp_get_default_device ();
   int id = omp_get_initial_device ();
-  void *p , *q;
+  int x;
+  void *p, *q;
+
+  q = (void *) &x;
 
   if (d < 0 || d >= omp_get_num_devices ())
     d = id;
@@ -18,7 +21,7 @@ main ()
   if (omp_target_associate_ptr (q, p, sizeof (int), 0, d) != 0)
     return 0;
 
-  if (omp_get_mapped_ptr (q, -1) != NULL)
+  if (omp_get_mapped_ptr (q, -5) != NULL)
     abort ();
 
   if (omp_get_mapped_ptr (q, omp_get_num_devices () + 1) != NULL)
@@ -27,6 +30,9 @@ main ()
   if (omp_get_mapped_ptr (q, id) != q)
     abort ();
 
+  if (omp_get_mapped_ptr (q, omp_initial_device) != q)
+    abort ();
+
   if (omp_get_mapped_ptr (q, d) != p)
     abort ();
 
--- libgomp/testsuite/libgomp.fortran/get-mapped-ptr-1.f90.jj	2022-05-09 09:09:20.963464303 +0200
+++ libgomp/testsuite/libgomp.fortran/get-mapped-ptr-1.f90	2022-06-15 09:43:11.632338293 +0200
@@ -19,7 +19,7 @@ program main
   if (omp_target_associate_ptr (c_loc (q), p, c_sizeof (q), &
                                 0_c_size_t, d) == 0) then
 
-    if(c_associated (omp_get_mapped_ptr (c_loc (q), -1))) &
+    if(c_associated (omp_get_mapped_ptr (c_loc (q), -5))) &
       stop 1
 
     if(c_associated (omp_get_mapped_ptr (c_loc (q), &
@@ -29,14 +29,18 @@ program main
     if(.not. c_associated (omp_get_mapped_ptr (c_loc (q), id), c_loc (q))) &
       stop 3
 
-    if(.not. c_associated (omp_get_mapped_ptr (c_loc (q), d), p)) &
+    if(.not. c_associated (omp_get_mapped_ptr (c_loc (q), omp_initial_device), &
+                           c_loc (q))) &
       stop 4
 
-    if (omp_target_disassociate_ptr (c_loc (q), d) /= 0) &
+    if(.not. c_associated (omp_get_mapped_ptr (c_loc (q), d), p)) &
       stop 5
 
-    if(c_associated (omp_get_mapped_ptr (c_loc (q), d))) &
+    if (omp_target_disassociate_ptr (c_loc (q), d) /= 0) &
       stop 6
+
+    if(c_associated (omp_get_mapped_ptr (c_loc (q), d))) &
+      stop 7
   end if
 
   call omp_target_free (p, d)


	Jakub


  reply	other threads:[~2022-06-15  8:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-13 12:06 Jakub Jelinek
2022-06-14 16:41 ` [committed] openmp: Conforming device numbers and omp_{initial, invalid}_device Thomas Schwinge
2022-06-15  8:46   ` Jakub Jelinek [this message]
2022-06-15 20:58     ` [committed] openmp: Conforming device numbers and omp_{initial,invalid}_device Thomas Schwinge

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=YqmcZiX9pJDYPRb0@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=marcel@codesourcery.com \
    --cc=thomas@codesourcery.com \
    --cc=tobias@codesourcery.com \
    /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).