]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
OpenMP: Fix regressions in metadirective-target-device-2.c [PR120518]
authorSandra Loosemore <sloosemore@baylibre.com>
Wed, 4 Jun 2025 04:03:03 +0000 (04:03 +0000)
committerSandra Loosemore <sloosemore@baylibre.com>
Thu, 5 Jun 2025 15:02:27 +0000 (15:02 +0000)
My previous patch that added a CLEANUP_POINT_EXPR around the device_num
selector expression in the C++ front end broke the testcase
c-c++-common/gomp/metadirective-target-device-2.c on offload targets.
It confused the code in omp_device_num_check that tries to bypass error
checking and do early resolution when the expression is a call to one
of the OpenMP library functions.  The solution is to make that code smart
enough to look inside a CLEANUP_POINT_EXPR.

gcc/ChangeLog
PR c++/120518
* omp-general.cc (omp_device_num_check): Look inside a
CLEANUP_POINT_EXPR when trying to optimize special cases.

(cherry picked from commit 9788a1e24822226b55dd1ab521e34bfaf9f4974d)

gcc/omp-general.cc

index 0eaa43156a5fcbbd4fe49caf7a9842086a154de9..6580a5f08ae81087c750ed98a88b3e4487b31b88 100644 (file)
@@ -2759,10 +2759,16 @@ omp_selector_is_dynamic (tree ctx)
 static tree
 omp_device_num_check (tree *device_num, bool *is_host)
 {
+  /* C++ may wrap the device_num expr in a CLEANUP_POINT_EXPR; we want
+     to look inside of it for the special cases.  */
+  tree t = *device_num;
+  if (TREE_CODE (t) == CLEANUP_POINT_EXPR)
+    t = TREE_OPERAND (t, 0);
+
   /* First check for some constant values we can treat specially.  */
-  if (tree_fits_shwi_p (*device_num))
+  if (tree_fits_shwi_p (t))
     {
-      HOST_WIDE_INT num = tree_to_shwi (*device_num);
+      HOST_WIDE_INT num = tree_to_shwi (t);
       if (num < -1)
        return integer_zero_node;
       /* Initial device?  */
@@ -2781,9 +2787,9 @@ omp_device_num_check (tree *device_num, bool *is_host)
 
   /* Also test for direct calls to OpenMP routines that return valid
      device numbers.  */
-  if (TREE_CODE (*device_num) == CALL_EXPR)
+  if (TREE_CODE (t) == CALL_EXPR)
     {
-      tree fndecl = get_callee_fndecl (*device_num);
+      tree fndecl = get_callee_fndecl (t);
       if (fndecl && omp_runtime_api_call (fndecl))
        {
          const char *fnname = IDENTIFIER_POINTER (DECL_NAME (fndecl));