Files
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

26 lines
621 B
C

// Check that no liboffload function is invoked without liboffload being
// initialized when offloading is disabled.
// RUN: %libomptarget-compile-generic
// RUN: env OMP_TARGET_OFFLOAD=disabled %libomptarget-run-generic 2>&1 | \
// RUN: %fcheck-generic --implicit-check-not="omptarget error"
#include <omp.h>
#include <stdio.h>
int main() {
int IsHost = 0;
#pragma omp target map(from : IsHost)
IsHost = omp_is_initial_device();
// CHECK: number of devices 0
printf("number of devices %d\n", omp_get_num_devices());
// CHECK: PASS
if (IsHost) {
printf("PASS\n");
return 0;
}
return 1;
}