Files
llvm/offload/test/offloading/disable_default_device.c
Hansang Bae 9945545d44 [Offload] Avoid invoking liboffload functions when uninitialized (#234645)
When libomptarget reads/detects `OMP_TARGET_OFFLOAD=disabled`, it skips
invoking `olInit()`, so subsequent calls to liboffload functions return
errors in most cases. This change adds minimal tracking of liboffload to
avoid such type of errors.

Assisted by Claude
2026-10-23 08:14:19 -05:00

22 lines
683 B
C

// RUN: %libomptarget-compile-generic
// RUN: env OMP_TARGET_OFFLOAD=disabled %libomptarget-run-generic 2>&1 | %fcheck-generic --implicit-check-not="omptarget error"
#include <omp.h>
#include <stdio.h>
// Sanity checks to make sure that this works and is thread safe.
int main() {
// CHECK: number of devices 0
printf("number of 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());
// CHECK: PASS
if (omp_get_initial_device() == omp_get_default_device()) {
printf("PASS\n");
return 0;
}
return 1;
}