Skip to content

[SPIR-V] Only emit __spirv__ when targeting HLSL #142401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion clang/lib/Basic/Targets/SPIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ void SPIR64TargetInfo::getTargetDefines(const LangOptions &Opts,
void BaseSPIRVTargetInfo::getTargetDefines(const LangOptions &Opts,
MacroBuilder &Builder) const {
DefineStd(Builder, "SPIRV", Opts);
DefineStd(Builder, "spirv", Opts);
if (Opts.HLSL)
DefineStd(Builder, "spirv", Opts);
}

void SPIRVTargetInfo::getTargetDefines(const LangOptions &Opts,
Expand Down
3 changes: 3 additions & 0 deletions clang/test/Preprocessor/predefined-macros.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,15 @@
// CHECK-SPIRV32-DAG: #define __SPIRV__ 1
// CHECK-SPIRV32-DAG: #define __SPIRV32__ 1
// CHECK-SPIRV32-NOT: #define __SPIRV64__ 1
// CHECK-SPIRV32-NOT: #define __spirv__ 1

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

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

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