[PATCH] D132056: [HLSL] Restrict to supported targets
Chris Bieneman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 30 12:08:46 PDT 2022
beanz updated this revision to Diff 456746.
beanz added a comment.
Adding the FIXME suggested by @aaron.ballman. Thanks!
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D132056/new/
https://reviews.llvm.org/D132056
Files:
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/Driver/hlsl-lang-targets.hlsl
clang/test/Preprocessor/predefined-macros-hlsl.c
Index: clang/test/Preprocessor/predefined-macros-hlsl.c
===================================================================
--- clang/test/Preprocessor/predefined-macros-hlsl.c
+++ clang/test/Preprocessor/predefined-macros-hlsl.c
@@ -29,20 +29,20 @@
// PIXEL: #define __SHADER_TARGET_STAGE 0
// VERTEX: #define __SHADER_TARGET_STAGE 1
-// RUN: %clang_cc1 %s -E -dM -o - -x hlsl -std=hlsl2015 | FileCheck -match-full-lines %s --check-prefixes=STD2015
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library %s -E -dM -o - -x hlsl -std=hlsl2015 | FileCheck -match-full-lines %s --check-prefixes=STD2015
// STD2015: #define __HLSL_VERSION 2015
-// RUN: %clang_cc1 %s -E -dM -o - -x hlsl -std=hlsl2016 | FileCheck -match-full-lines %s --check-prefixes=STD2016
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library %s -E -dM -o - -x hlsl -std=hlsl2016 | FileCheck -match-full-lines %s --check-prefixes=STD2016
// STD2016: #define __HLSL_VERSION 2016
-// RUN: %clang_cc1 %s -E -dM -o - -x hlsl -std=hlsl2017 | FileCheck -match-full-lines %s --check-prefixes=STD2017
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library %s -E -dM -o - -x hlsl -std=hlsl2017 | FileCheck -match-full-lines %s --check-prefixes=STD2017
// STD2017: #define __HLSL_VERSION 2017
-// RUN: %clang_cc1 %s -E -dM -o - -x hlsl -std=hlsl2018 | FileCheck -match-full-lines %s --check-prefixes=STD2018
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library %s -E -dM -o - -x hlsl -std=hlsl2018 | FileCheck -match-full-lines %s --check-prefixes=STD2018
// STD2018: #define __HLSL_VERSION 2018
-// RUN: %clang_cc1 %s -E -dM -o - -x hlsl -std=hlsl2021 | FileCheck -match-full-lines %s --check-prefixes=STD2021
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library %s -E -dM -o - -x hlsl -std=hlsl2021 | FileCheck -match-full-lines %s --check-prefixes=STD2021
// STD2021: #define __HLSL_VERSION 2021
-// RUN: %clang_cc1 %s -E -dM -o - -x hlsl -std=hlsl202x | FileCheck -match-full-lines %s --check-prefixes=STD202x
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library %s -E -dM -o - -x hlsl -std=hlsl202x | FileCheck -match-full-lines %s --check-prefixes=STD202x
// STD202x: #define __HLSL_VERSION 2029
Index: clang/test/Driver/hlsl-lang-targets.hlsl
===================================================================
--- /dev/null
+++ clang/test/Driver/hlsl-lang-targets.hlsl
@@ -0,0 +1,14 @@
+// RUN: not %clang -target x86_64-unknown-unknown %s 2>&1 | FileCheck %s --check-prefix=X86
+// RUN: not %clang -target dxil-unknown-unknown %s 2>&1 | FileCheck %s --check-prefix=DXIL
+// RUN: not %clang -target x86_64-unknown-shadermodel %s 2>&1 | FileCheck %s --check-prefix=SM
+// RUN: not %clang -target spirv64-unknown-unknown %s 2>&1 | FileCheck %s --check-prefix=SPIRV
+
+
+// A completely unsupported target...
+// X86: error: HLSL code generation is unsupported for target 'x86_64-unknown-unknown'
+
+// Poorly specified targets
+// DXIL: error: HLSL code generation is unsupported for target 'dxil-unknown-unknown'
+// SM: error: HLSL code generation is unsupported for target 'x86_64-unknown-shadermodel'
+
+// FIXME// SPIRV: error: HLSL code generation is unsupported for target 'spirv64-unknown-unknown'
Index: clang/lib/Frontend/CompilerInvocation.cpp
===================================================================
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -4111,6 +4111,14 @@
if (const Arg *A = Args.getLastArg(OPT_frandomize_layout_seed_EQ))
Opts.RandstructSeed = A->getValue(0);
+ // Validate options for HLSL
+ if (Opts.HLSL) {
+ bool SupportedTarget = T.getArch() == llvm::Triple::dxil &&
+ T.getOS() == llvm::Triple::ShaderModel;
+ if (!SupportedTarget)
+ Diags.Report(diag::err_drv_hlsl_unsupported_target) << T.str();
+ }
+
return Diags.getNumErrors() == NumErrorsBefore;
}
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -668,6 +668,8 @@
"invalid profile : %0">;
def err_drv_dxc_missing_target_profile : Error<
"target profile option (-T) is missing">;
+def err_drv_hlsl_unsupported_target : Error<
+ "HLSL code generation is unsupported for target '%0'">;
def err_drv_invalid_range_dxil_validator_version : Error<
"invalid validator version : %0\n"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132056.456746.patch
Type: text/x-patch
Size: 4494 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220830/f3ac5af1/attachment-0001.bin>
More information about the cfe-commits
mailing list