diff --git a/clang/lib/Basic/Targets/NVPTX.cpp b/clang/lib/Basic/Targets/NVPTX.cpp --- a/clang/lib/Basic/Targets/NVPTX.cpp +++ b/clang/lib/Basic/Targets/NVPTX.cpp @@ -168,7 +168,7 @@ MacroBuilder &Builder) const { Builder.defineMacro("__PTX__"); Builder.defineMacro("__NVPTX__"); - if (Opts.CUDAIsDevice || Opts.OpenMPIsDevice) { + if (Opts.CUDAIsDevice || Opts.OpenMPIsDevice || !HostTarget) { // Set __CUDA_ARCH__ for the GPU specified. std::string CUDAArchCode = [this] { switch (GPU) { diff --git a/clang/test/Frontend/standalone-nvptx-macros.c b/clang/test/Frontend/standalone-nvptx-macros.c new file mode 100644 --- /dev/null +++ b/clang/test/Frontend/standalone-nvptx-macros.c @@ -0,0 +1,5 @@ +// REQUIRES: nvptx-registered-target + +// RUN: %clang %s -c -E -dM --target=nvptx64-nvidia-cuda -march=sm_70 -o - | \ +// RUN: FileCheck --check-prefix=CHECK-CUDA-ARCH %s +// CHECK-CUDA-ARCH: #define __CUDA_ARCH__ 700