[llvm] [openmp] [OpenMP][Runtime] Handling crash with `OMP_TARGET_OFFLOAD=DISABLED` and invoking `omp_get_default_device()` (PR #171789)

via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 11 02:01:55 PST 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions c,h -- offload/test/api/omp_get_default_device_test.c offload/test/offloading/target_offload_disabled_default_device.c openmp/runtime/test/env/omp_target_offload_default_device_combined.c openmp/runtime/test/env/omp_target_offload_default_device_nested.c openmp/runtime/test/env/omp_target_offload_default_device_operations.c openmp/runtime/test/env/omp_target_offload_default_device_simple.c openmp/runtime/test/env/omp_target_offload_default_device_target.c openmp/runtime/test/env/omp_target_offload_default_device_threads.c openmp/runtime/src/kmp_ftn_entry.h --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/offload/test/api/omp_get_default_device_test.c b/offload/test/api/omp_get_default_device_test.c
index a5c7e8389..b1ca66cd5 100644
--- a/offload/test/api/omp_get_default_device_test.c
+++ b/offload/test/api/omp_get_default_device_test.c
@@ -1,5 +1,6 @@
 // RUN: %libomptarget-compile-generic
-// RUN: env OMP_TARGET_OFFLOAD=disabled %libomptarget-run-generic 2>&1 | %fcheck-generic
+// RUN: env OMP_TARGET_OFFLOAD=disabled %libomptarget-run-generic 2>&1 |
+// %fcheck-generic
 //
 // Test omp_get_default_device() API behavior when offload is disabled
 
diff --git a/offload/test/offloading/target_offload_disabled_default_device.c b/offload/test/offloading/target_offload_disabled_default_device.c
index 168076ad8..20b40a43b 100644
--- a/offload/test/offloading/target_offload_disabled_default_device.c
+++ b/offload/test/offloading/target_offload_disabled_default_device.c
@@ -1,5 +1,6 @@
 // RUN: %libomptarget-compile-generic
-// RUN: env OMP_TARGET_OFFLOAD=disabled %libomptarget-run-generic 2>&1 | %fcheck-generic
+// RUN: env OMP_TARGET_OFFLOAD=disabled %libomptarget-run-generic 2>&1 |
+// %fcheck-generic
 //
 // Test that setting default device before disabling offload doesn't crash
 
@@ -9,37 +10,36 @@
 int main() {
   // Set high default device number
   omp_set_default_device(5);
-  
+
   // This simulates OMP_TARGET_OFFLOAD=disabled being set after device is chosen
   // In practice, the environment variable is read at runtime init
-  
+
   // CHECK: num_devices: 0
   printf("num_devices: %d\n", omp_get_num_devices());
-  
+
   // CHECK: initial_device: 0
   printf("initial_device: %d\n", omp_get_initial_device());
-  
+
   // CHECK: default_device: 0
   printf("default_device: %d\n", omp_get_default_device());
-  
+
   // Target region should execute on host
   int result = -1;
-  #pragma omp target map(from: result)
+#pragma omp target map(from : result)
   {
     result = omp_get_device_num();
   }
-  
+
   // CHECK: executed_on: 0
   printf("executed_on: %d\n", result);
-  
+
   // CHECK: PASS
-  if (result == omp_get_initial_device() && 
+  if (result == omp_get_initial_device() &&
       omp_get_default_device() == omp_get_initial_device()) {
     printf("PASS\n");
     return 0;
   }
-  
+
   printf("FAIL\n");
   return 1;
 }
-

``````````

</details>


https://github.com/llvm/llvm-project/pull/171789


More information about the llvm-commits mailing list