[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,89 @@
+// RUN: %libomp-compile-and-run
+// REQUIRES: ompt
+//
+// Test that device operations using omp_get_default_device() don't crash
+// when OMP_TARGET_OFFLOAD=DISABLED. This simulates real-world usage where
+// the default device is used for device-specific operations.
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <omp.h>
+
+extern void kmp_set_defaults(char const *str);
+
+int main() {
+  // Simulate the problematic scenario: high default device number + disabled
+  // offload Use API call instead of env var to ensure ICV is set
+  omp_set_default_device(10);
----------------
jprotze wrote:

This function already triggers `__kmp_do_serial_initialize()`. Does the kmp_set_defaults below have any effect after serial init?

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


More information about the llvm-commits mailing list