[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 11:09:14 PST 2024


https://github.com/bob80905 updated https://github.com/llvm/llvm-project/pull/84537

>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] 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 1bc9885849d54b..23009117af0f37 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 c6ad862b229420..e30ae78ca6553c 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;
 }
 



More information about the cfe-commits mailing list