[clang] [HIP] Define `_OPENMP` on the device for mixed OpenMP CPU compilations (PR #176791)

Joseph Huber via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 20 05:29:14 PST 2026


================
@@ -1460,6 +1460,11 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
     }
   }
 
+  // CUDA / HIP offloading only supports OpenMP's CPU support, but both
+  // compilations must define these macros to compile.
+  if (LangOpts.OpenMPMacros)
+    Builder.defineMacro("_OPENMP", "0");
----------------
jhuber6 wrote:

Only device code should be compiled, which shouldn't contain any OpenMP pragmas. If you set this to a high value it would make `omp.h` stop working because it uses OpenMP  variants to define some functions. I just take this to mean that it doesn't exist, but no code on the GPU should be using it anyway. This is definitely a hack so I could see complaining to CMake about it instead.

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


More information about the cfe-commits mailing list