[Openmp-commits] [llvm] [openmp] [OpenMP][Runtime] Handling crash with OMP_TARGET_OFFLOAD=DISABLED and invalid default device (PR #173630)
via Openmp-commits
openmp-commits at lists.llvm.org
Fri Dec 26 03:06:26 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,cpp,h -- offload/test/api/omp_set_default_device_disabled.c offload/test/offloading/target_offload_disabled_set_default_device_api.c offload/test/offloading/target_offload_disabled_set_default_device_env.c offload/test/offloading/target_offload_disabled_set_default_device_stress.c openmp/runtime/test/env/omp_target_offload_disabled_set_default_device.c openmp/runtime/test/env/omp_target_offload_disabled_set_default_device_combined.c openmp/runtime/test/env/omp_target_offload_disabled_set_default_device_icv.c openmp/runtime/test/env/omp_target_offload_disabled_set_default_device_nested.c openmp/runtime/test/env/omp_target_offload_disabled_set_default_device_threads.c openmp/runtime/src/kmp_ftn_entry.h openmp/runtime/src/kmp_runtime.cpp --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_set_default_device_disabled.c b/offload/test/api/omp_set_default_device_disabled.c
index 5a44b0437..e22620058 100644
--- a/offload/test/api/omp_set_default_device_disabled.c
+++ b/offload/test/api/omp_set_default_device_disabled.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
//
// API test: omp_set_default_device() should clamp to initial_device
// when OMP_TARGET_OFFLOAD=disabled
@@ -35,7 +36,8 @@ int main() {
// Test 3: All should be equal to initial
// CHECK: All equal: YES
- printf("All equal: %s\n", (dev1 == initial && dev2 == initial) ? "YES" : "NO");
+ printf("All equal: %s\n",
+ (dev1 == initial && dev2 == initial) ? "YES" : "NO");
// Test 4: Target region should work
int executed = 0;
diff --git a/offload/test/offloading/target_offload_disabled_set_default_device_api.c b/offload/test/offloading/target_offload_disabled_set_default_device_api.c
index 6a6beac03..e2e602931 100644
--- a/offload/test/offloading/target_offload_disabled_set_default_device_api.c
+++ b/offload/test/offloading/target_offload_disabled_set_default_device_api.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
//
// Integration test: omp_set_default_device() should not cause crashes
// and target regions should work when offload is disabled
diff --git a/offload/test/offloading/target_offload_disabled_set_default_device_env.c b/offload/test/offloading/target_offload_disabled_set_default_device_env.c
index 50949b6d9..3934f4211 100644
--- a/offload/test/offloading/target_offload_disabled_set_default_device_env.c
+++ b/offload/test/offloading/target_offload_disabled_set_default_device_env.c
@@ -1,5 +1,6 @@
// RUN: %libomptarget-compile-generic
-// RUN: env OMP_DEFAULT_DEVICE=5 OMP_TARGET_OFFLOAD=disabled %libomptarget-run-generic 2>&1 | %fcheck-generic
+// RUN: env OMP_DEFAULT_DEVICE=5 OMP_TARGET_OFFLOAD=disabled
+// %libomptarget-run-generic 2>&1 | %fcheck-generic
//
// Integration test: OMP_DEFAULT_DEVICE environment variable is properly
// overridden when offload is disabled
diff --git a/offload/test/offloading/target_offload_disabled_set_default_device_stress.c b/offload/test/offloading/target_offload_disabled_set_default_device_stress.c
index d3b24436d..b1197849b 100644
--- a/offload/test/offloading/target_offload_disabled_set_default_device_stress.c
+++ b/offload/test/offloading/target_offload_disabled_set_default_device_stress.c
@@ -1,5 +1,6 @@
// RUN: %libomptarget-compile-generic
-// RUN: env OMP_TARGET_OFFLOAD=disabled OMP_DEFAULT_DEVICE=99 %libomptarget-run-generic 2>&1 | %fcheck-generic
+// RUN: env OMP_TARGET_OFFLOAD=disabled OMP_DEFAULT_DEVICE=99
+// %libomptarget-run-generic 2>&1 | %fcheck-generic
//
// Stress test: Multiple scenarios with offload disabled to ensure robustness
diff --git a/openmp/runtime/test/env/omp_target_offload_disabled_set_default_device.c b/openmp/runtime/test/env/omp_target_offload_disabled_set_default_device.c
index 253278cb6..629562ab4 100644
--- a/openmp/runtime/test/env/omp_target_offload_disabled_set_default_device.c
+++ b/openmp/runtime/test/env/omp_target_offload_disabled_set_default_device.c
@@ -38,7 +38,8 @@ int main() {
if (default_device != initial_device) {
fprintf(stderr, "FAIL: Setter didn't clamp to initial_device\n");
- fprintf(stderr, " Expected %d, got %d\n", initial_device, default_device);
+ fprintf(stderr, " Expected %d, got %d\n", initial_device,
+ default_device);
return EXIT_FAILURE;
}
diff --git a/openmp/runtime/test/env/omp_target_offload_disabled_set_default_device_combined.c b/openmp/runtime/test/env/omp_target_offload_disabled_set_default_device_combined.c
index 8a9196fa6..dc8bb14ae 100644
--- a/openmp/runtime/test/env/omp_target_offload_disabled_set_default_device_combined.c
+++ b/openmp/runtime/test/env/omp_target_offload_disabled_set_default_device_combined.c
@@ -1,7 +1,7 @@
// RUN: %libomp-compile-and-run
//
-// Test combined scenario: OMP_DEFAULT_DEVICE env var + omp_set_default_device() API
-// Both should be overridden when OMP_TARGET_OFFLOAD=DISABLED
+// Test combined scenario: OMP_DEFAULT_DEVICE env var + omp_set_default_device()
+// API Both should be overridden when OMP_TARGET_OFFLOAD=DISABLED
#include <stdio.h>
#include <stdlib.h>
diff --git a/openmp/runtime/test/env/omp_target_offload_disabled_set_default_device_icv.c b/openmp/runtime/test/env/omp_target_offload_disabled_set_default_device_icv.c
index e5793ee73..11c719ac1 100644
--- a/openmp/runtime/test/env/omp_target_offload_disabled_set_default_device_icv.c
+++ b/openmp/runtime/test/env/omp_target_offload_disabled_set_default_device_icv.c
@@ -1,8 +1,8 @@
// RUN: %libomp-compile-and-run
//
-// Test that the ICV (Internal Control Variable) itself contains the correct value
-// This verifies spec compliance: omp_get_default_device() returns the ICV value,
-// and the setter ensures the ICV is always valid.
+// Test that the ICV (Internal Control Variable) itself contains the correct
+// value This verifies spec compliance: omp_get_default_device() returns the ICV
+// value, and the setter ensures the ICV is always valid.
#include <stdio.h>
#include <stdlib.h>
@@ -44,8 +44,8 @@ int main() {
for (int i = 0; i < 5; i++) {
omp_set_default_device(test_values[i]);
int dev = omp_get_default_device();
- printf("Test 3.%d - After set(%d): default_device = %d\n",
- i, test_values[i], dev);
+ printf("Test 3.%d - After set(%d): default_device = %d\n", i,
+ test_values[i], dev);
if (dev != initial_device) {
fprintf(stderr, "FAIL: Set(%d) resulted in %d\n", test_values[i], dev);
return EXIT_FAILURE;
diff --git a/openmp/runtime/test/env/omp_target_offload_disabled_set_default_device_nested.c b/openmp/runtime/test/env/omp_target_offload_disabled_set_default_device_nested.c
index cfcaab498..79851dd0e 100644
--- a/openmp/runtime/test/env/omp_target_offload_disabled_set_default_device_nested.c
+++ b/openmp/runtime/test/env/omp_target_offload_disabled_set_default_device_nested.c
@@ -14,8 +14,8 @@ int check_device(const char *context) {
int initial_dev = omp_get_initial_device();
if (default_dev != initial_dev) {
- fprintf(stderr, "FAIL [%s]: default=%d, initial=%d\n",
- context, default_dev, initial_dev);
+ fprintf(stderr, "FAIL [%s]: default=%d, initial=%d\n", context, default_dev,
+ initial_dev);
return 1;
}
return 0;
@@ -65,7 +65,8 @@ int main() {
errors += check_device("sequential final");
// Test 5: Target region execution (only use well-defined functions)
- // Note: Calling omp_get_default_device() from within target region is unspecified
+ // Note: Calling omp_get_default_device() from within target region is
+ // unspecified
int target_errors = 0;
#pragma omp target map(tofrom : target_errors)
{
diff --git a/openmp/runtime/test/env/omp_target_offload_disabled_set_default_device_threads.c b/openmp/runtime/test/env/omp_target_offload_disabled_set_default_device_threads.c
index b84c08986..e61a07162 100644
--- a/openmp/runtime/test/env/omp_target_offload_disabled_set_default_device_threads.c
+++ b/openmp/runtime/test/env/omp_target_offload_disabled_set_default_device_threads.c
@@ -23,8 +23,8 @@ int main() {
int initial_device = omp_get_initial_device();
int errors = 0;
- printf("Multi-threaded test: %d threads, %d iterations each\n",
- NUM_THREADS, NUM_ITERATIONS);
+ printf("Multi-threaded test: %d threads, %d iterations each\n", NUM_THREADS,
+ NUM_ITERATIONS);
printf("initial_device = %d\n", initial_device);
#pragma omp parallel num_threads(NUM_THREADS) reduction(+ : errors)
``````````
</details>
https://github.com/llvm/llvm-project/pull/173630
More information about the Openmp-commits
mailing list