[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 07:13:16 PST 2025
================
@@ -0,0 +1,45 @@
+// RUN: %libomptarget-compile-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
+
+#include <omp.h>
+#include <stdio.h>
+
+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());
----------------
jprotze wrote:
Can also return `omp_initial_device`, i.e. `-1`.
https://github.com/llvm/llvm-project/pull/171789
More information about the llvm-commits
mailing list