[clang] [HLSL] Add diagnostic for enabling 16 bit types (PR #84537)
Joshua Batista via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 8 15:29:36 PST 2024
https://github.com/bob80905 updated https://github.com/llvm/llvm-project/pull/84537
>From 55395c5c8a5b92e200aa2f1bf06774d20ac4afd9 Mon Sep 17 00:00:00 2001
From: Joshua Batista <jbatista at microsoft.com>
Date: Fri, 8 Mar 2024 11:03:37 -0800
Subject: [PATCH 1/3] add check for enable 16 bit types
---
clang/include/clang/Basic/DiagnosticDriverKinds.td | 3 ++-
clang/lib/Driver/ToolChains/HLSL.cpp | 14 ++++++++++++++
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 1bc9885849d54bf..23009117af0f378 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -750,7 +750,8 @@ def err_drv_hlsl_unsupported_target : Error<
"HLSL code generation is unsupported for target '%0'">;
def err_drv_hlsl_bad_shader_required_in_target : Error<
"%select{shader model|Vulkan environment|shader stage}0 is required as %select{OS|environment}1 in target '%2' for HLSL code generation">;
-
+def err_drv_hlsl_enable_16bit_types : Error<
+ "enable_16bit_types cannot be applied when shader model is <= 6.2 and hlsl version <= 2018. (SM: %0, HV: %1)">;
def err_drv_hlsl_bad_shader_unsupported : Error<
"%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' is invalid for HLSL code generation">;
def warn_drv_dxc_missing_dxv : Warning<"dxv not found. "
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp b/clang/lib/Driver/ToolChains/HLSL.cpp
index c6ad862b229420b..e30ae78ca6553cf 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -243,6 +243,20 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch,
// FIXME: add validation for enable_16bit_types should be after HLSL 2018 and
// shader model 6.2.
// See: https://github.com/llvm/llvm-project/issues/57876
+ if (DAL->hasArg(options::OPT_enable_16bit_types)) {
+ llvm::opt::Arg *hvArg = DAL->getLastArg(options::OPT_dxc_hlsl_version);
+ llvm::VersionTuple versionTuple = getTriple().getOSVersion();
+ unsigned int major = versionTuple.getMajor();
+ auto minor = versionTuple.getMinor();
+
+ if (major < 6 || (major == 6 && minor.value() <= 2) ||
+ strcmp(hvArg->getValue(), "2016") == 0 ||
+ strcmp(hvArg->getValue(), "2017") == 0 ||
+ strcmp(hvArg->getValue(), "2018") == 0) {
+ getDriver().Diag(diag::err_drv_hlsl_enable_16bit_types)
+ << versionTuple.getAsString() << hvArg->getValue();
+ }
+ }
return DAL;
}
>From 8205c6894a4c1deeeb28c2520d16a56c3fcf21ea Mon Sep 17 00:00:00 2001
From: Joshua Batista <jbatista at microsoft.com>
Date: Fri, 8 Mar 2024 11:03:37 -0800
Subject: [PATCH 2/3] add check for enable 16 bit types
---
clang/include/clang/Basic/DiagnosticDriverKinds.td | 3 ++-
clang/lib/Driver/ToolChains/HLSL.cpp | 14 ++++++++++++++
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 1bc9885849d54bf..23009117af0f378 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -750,7 +750,8 @@ def err_drv_hlsl_unsupported_target : Error<
"HLSL code generation is unsupported for target '%0'">;
def err_drv_hlsl_bad_shader_required_in_target : Error<
"%select{shader model|Vulkan environment|shader stage}0 is required as %select{OS|environment}1 in target '%2' for HLSL code generation">;
-
+def err_drv_hlsl_enable_16bit_types : Error<
+ "enable_16bit_types cannot be applied when shader model is <= 6.2 and hlsl version <= 2018. (SM: %0, HV: %1)">;
def err_drv_hlsl_bad_shader_unsupported : Error<
"%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' is invalid for HLSL code generation">;
def warn_drv_dxc_missing_dxv : Warning<"dxv not found. "
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp b/clang/lib/Driver/ToolChains/HLSL.cpp
index c6ad862b229420b..e30ae78ca6553cf 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -243,6 +243,20 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch,
// FIXME: add validation for enable_16bit_types should be after HLSL 2018 and
// shader model 6.2.
// See: https://github.com/llvm/llvm-project/issues/57876
+ if (DAL->hasArg(options::OPT_enable_16bit_types)) {
+ llvm::opt::Arg *hvArg = DAL->getLastArg(options::OPT_dxc_hlsl_version);
+ llvm::VersionTuple versionTuple = getTriple().getOSVersion();
+ unsigned int major = versionTuple.getMajor();
+ auto minor = versionTuple.getMinor();
+
+ if (major < 6 || (major == 6 && minor.value() <= 2) ||
+ strcmp(hvArg->getValue(), "2016") == 0 ||
+ strcmp(hvArg->getValue(), "2017") == 0 ||
+ strcmp(hvArg->getValue(), "2018") == 0) {
+ getDriver().Diag(diag::err_drv_hlsl_enable_16bit_types)
+ << versionTuple.getAsString() << hvArg->getValue();
+ }
+ }
return DAL;
}
>From 3d3d5dd364b9d816670920d8fe53b684c6598564 Mon Sep 17 00:00:00 2001
From: Joshua Batista <jbatista at microsoft.com>
Date: Fri, 8 Mar 2024 15:29:21 -0800
Subject: [PATCH 3/3] remove stale comment
---
clang/lib/Driver/ToolChains/HLSL.cpp | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp b/clang/lib/Driver/ToolChains/HLSL.cpp
index e30ae78ca6553cf..2e05b9534ded270 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -240,9 +240,7 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch,
if (!DAL->hasArg(options::OPT_O_Group)) {
DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_O), "3");
}
- // FIXME: add validation for enable_16bit_types should be after HLSL 2018 and
- // shader model 6.2.
- // See: https://github.com/llvm/llvm-project/issues/57876
+
if (DAL->hasArg(options::OPT_enable_16bit_types)) {
llvm::opt::Arg *hvArg = DAL->getLastArg(options::OPT_dxc_hlsl_version);
llvm::VersionTuple versionTuple = getTriple().getOSVersion();
More information about the cfe-commits
mailing list