Skip to content

Commit df5f65d

Browse files
authored
[SPIR-V] Only emit __spirv__ when targeting HLSL (#142401)
OpenCL translator has a `__spirv` namespace, and defining the `__spirv__` macro causes issues downstream on the OpenCL side. This macro is needed to keep compatibility with HLSL/DXC, but can be avoided for other targets/languages.
1 parent 847e403 commit df5f65d

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

clang/lib/Basic/Targets/SPIR.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ void SPIR64TargetInfo::getTargetDefines(const LangOptions &Opts,
8787
void BaseSPIRVTargetInfo::getTargetDefines(const LangOptions &Opts,
8888
MacroBuilder &Builder) const {
8989
DefineStd(Builder, "SPIRV", Opts);
90-
DefineStd(Builder, "spirv", Opts);
90+
if (Opts.HLSL)
91+
DefineStd(Builder, "spirv", Opts);
9192
}
9293

9394
void SPIRVTargetInfo::getTargetDefines(const LangOptions &Opts,

clang/test/Preprocessor/predefined-macros.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,15 @@
228228
// CHECK-SPIRV32-DAG: #define __SPIRV__ 1
229229
// CHECK-SPIRV32-DAG: #define __SPIRV32__ 1
230230
// CHECK-SPIRV32-NOT: #define __SPIRV64__ 1
231+
// CHECK-SPIRV32-NOT: #define __spirv__ 1
231232

232233
// RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spirv64-unknown-unknown \
233234
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIRV64
234235
// CHECK-SPIRV64-DAG: #define __IMAGE_SUPPORT__ 1
235236
// CHECK-SPIRV64-DAG: #define __SPIRV__ 1
236237
// CHECK-SPIRV64-DAG: #define __SPIRV64__ 1
237238
// CHECK-SPIRV64-NOT: #define __SPIRV32__ 1
239+
// CHECK-SPIRV64-NOT: #define __spirv__ 1
238240

239241
// RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spirv64-amd-amdhsa \
240242
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIRV64-AMDGCN
@@ -245,6 +247,7 @@
245247
// CHECK-SPIRV64-AMDGCN-DAG: #define __AMDGCN__ 1
246248
// CHECK-SPIRV64-AMDGCN-DAG: #define __AMDGPU__ 1
247249
// CHECK-SPIRV64-AMDGCN-NOT: #define __SPIRV32__ 1
250+
// CHECK-SPIRV64-AMDGCN-NOT: #define __spirv__ 1
248251

249252
// RUN: %clang_cc1 %s -E -dM -o - -x hip -triple x86_64-unknown-linux-gnu \
250253
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-HIP

0 commit comments

Comments
 (0)