[gcc/devel/omp/gcc-16] libgomp: Handle omp_default_device in the fallback case [PR125951]

Sandra Loosemore via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:c61ff485240636591ca9ef5ea0ba7490580c31c0

commit c61ff485240636591ca9ef5ea0ba7490580c31c0
Author: Tobias Burnus <[email protected]>
Date:   Wed Jun 24 06:30:25 2026 +0200

    libgomp: Handle omp_default_device in the fallback case [PR125951]
    
    Support for omp_default_device was added before the commit
    r17-1702-g8af1592882509f for the Linux case, but for the fallback
    case, it was missed - such that the testcase failed on all
    non-Linux systems.
    
    libgomp/ChangeLog:
    
            PR libgomp/125951
    
            * target.c (omp_get_device_distances): Handle omp_default_device
            in the fallback code.
    
    (cherry picked from commit 23aa47659828ae13898b76b1516f17fef8562a7e)

Diff:
---
 libgomp/target.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/libgomp/target.c b/libgomp/target.c
index 9c0b012d142f..381e85179fd1 100644
--- a/libgomp/target.c
+++ b/libgomp/target.c
@@ -6153,12 +6153,17 @@ omp_get_device_distances (int ndevs, const int *devs, int *distances)
   if (node < 0) /* Not supported. */
     {
       for (int i = 0; i < ndevs; i++)
-	if (devs[i] < omp_initial_device || devs[i] > num_devices)
-	  distances[i] = -1;  /* invalid */
-	else if (devs[i] == omp_initial_device || devs[i] == num_devices)
-	  distances[i] = 0;
-	else
-	  distances[i] = 10;
+	{
+	  int device_num = (devs[i] == omp_default_device
+			    ? gomp_get_default_device () : devs[i]);
+	  if (device_num < omp_initial_device || device_num > num_devices)
+	    distances[i] = -1;  /* invalid */
+	  else if (device_num == omp_initial_device
+		   || device_num == num_devices)
+	    distances[i] = 0;
+	  else
+	    distances[i] = 10;
+	}
       return;
     }
   for (int i = 0; i < ndevs; i++)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.