[Openmp-commits] [clang] [llvm] [openmp] [Clang][OpenMP] Validate omp_initial_device omp_invalid_device as device IDs (PR #193688)

Jan André Reuter via Openmp-commits openmp-commits at lists.llvm.org
Thu Apr 23 02:51:05 PDT 2026


================
@@ -0,0 +1,52 @@
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=52 -ferror-limit 100 %s -Wuninitialized
+// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=52 -ferror-limit 100 %s -Wuninitialized
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=60 -ferror-limit 100 %s -Wuninitialized
+
+// expected-no-diagnostics
+
+#define omp_initial_device -1
+#define omp_invalid_device -2
+
+void foo(void) {}
+
+int main(void) {
+  int a = 0;
+
+  // Literal values allowed by the spec for the 'device' clause.
+  #pragma omp target device(-1)
+  foo();
+  #pragma omp target device(-2)
+  foo();
+  #pragma omp target device(0)
+  foo();
+  #pragma omp target device(1)
+  foo();
+
+  // Using the predefined identifiers.
+  #pragma omp target device(omp_initial_device)
+  foo();
+  #pragma omp target device(omp_invalid_device)
+  foo();
+
+  // Also accepted on other target-capable directives.
+  #pragma omp target data map(to: a) device(omp_initial_device)
+  foo();
+  #pragma omp target data map(to: a) device(omp_invalid_device)
+  foo();
+
+  #pragma omp target enter data map(to: a) device(omp_initial_device)
+  #pragma omp target enter data map(to: a) device(omp_invalid_device)
+
+  #pragma omp target exit data map(from: a) device(omp_initial_device)
+  #pragma omp target exit data map(from: a) device(omp_invalid_device)
+
+  #pragma omp target update to(a) device(omp_initial_device)
+  #pragma omp target update to(a) device(omp_invalid_device)
+
+  // Runtime-determined device numbers still pass (no compile-time check).
+  int dev = -1;
+  #pragma omp target device(dev)
+  foo();
----------------
Thyre wrote:

Shouldn't this use e.g. `-3` to ensure that this isn't an accepted number by mistake?
`-1` could accidentally pass due to it being `omp_initial_device`.

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


More information about the Openmp-commits mailing list