Skip to content

[HLSL] Add -Gis option to clang-dxc #146448

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bob80905
Copy link
Contributor

@bob80905 bob80905 commented Jul 1, 2025

This PR adds the -Gis option to clang-dxc, to instruct the behavior to enable IEEE strict mode. The purpose is so that clang-dxc behaves as DXC does when it takes the -Gis option.
Fixes #145589

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' HLSL HLSL Language Support labels Jul 1, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 1, 2025

@llvm/pr-subscribers-hlsl

@llvm/pr-subscribers-clang-driver

Author: Joshua Batista (bob80905)

Changes

This PR adds the -Gis option to clang-dxc, to instruct the behavior to enable IEEE strict mode. The purpose is so that clang-dxc behaves as DXC does when it takes the -Gis option.
Fixes #145589


Full diff: https://github.com/llvm/llvm-project/pull/146448.diff

3 Files Affected:

  • (modified) clang/include/clang/Driver/Options.td (+2)
  • (modified) clang/lib/Driver/ToolChains/HLSL.cpp (+8)
  • (added) clang/test/Options/Gis.hlsl (+12)
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 0ffd8c40da7da..a1e56e2ec9b8c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -9306,6 +9306,8 @@ def dxc_validator_path_EQ : Joined<["--"], "dxv-path=">, Group<dxc_Group>,
   HelpText<"DXIL validator installation path">;
 def dxc_disable_validation : DXCFlag<"Vd">,
   HelpText<"Disable validation">;
+def dxc_gis : DXCFlag<"Gis">,
+  HelpText<"Enable IEEE strict mode (equivalent to -ffp-model=strict)">;
 def : Option<["/", "-"], "Qembed_debug", KIND_FLAG>, Group<dxc_Group>,
   Flags<[Ignored]>, Visibility<[DXCOption]>,
   HelpText<"Embed PDB in shader container (ignored)">;
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp b/clang/lib/Driver/ToolChains/HLSL.cpp
index dcc51e182924c..4a4938a501e9e 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -330,6 +330,14 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch,
       A->claim();
       continue;
     }
+    if (A->getOption().getID() == options::OPT_dxc_gis) {
+      // Translate -Gis into -ffp_model_EQ=strict
+      DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_ffp_model_EQ),
+                          "strict");
+      A->claim();
+      continue;
+    }
+
     DAL->append(A);
   }
 
diff --git a/clang/test/Options/Gis.hlsl b/clang/test/Options/Gis.hlsl
new file mode 100644
index 0000000000000..5a11b7ba64ff0
--- /dev/null
+++ b/clang/test/Options/Gis.hlsl
@@ -0,0 +1,12 @@
+// RUN: %clang_dxc -T lib_6_4 -Gis %s 2>&1 -### | FileCheck -check-prefix=Gis %s
+// RUN: %clang_dxc -T lib_6_4 %s 2>&1 -### | FileCheck -check-prefix=NO_Gis %s
+// RUN: not %clang_dxc -T lib_6_4 /Gis gibberish -### %s 2>&1 | FileCheck -check-prefix=CHECK-ERR %s
+
+// Gis: "-fmath-errno" "-ffp-contract=off" "-frounding-math" "-ffp-exception-behavior=strict" "-complex-range=full"
+// assert expected floating point options are present
+// NO_Gis-NOT: "-fmath-errno" "-ffp-contract=off" "-frounding-math" "-ffp-exception-behavior=strict" "-complex-range=full"
+// CHECK-ERR: error: no such file or directory: 'gibberish'
+float4 main(float4 a : A) : SV_TARGET
+{
+  return -a.yxxx;
+}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category HLSL HLSL Language Support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[HLSL] Add -Gis option from DXC to clang-dxc
2 participants