diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -666,6 +666,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" diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -4107,6 +4107,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; } diff --git a/clang/test/CodeGenHLSL/validator_version.hlsl b/clang/test/CodeGenHLSL/validator_version.hlsl --- a/clang/test/CodeGenHLSL/validator_version.hlsl +++ b/clang/test/CodeGenHLSL/validator_version.hlsl @@ -1,5 +1,7 @@ // RUN: %clang -cc1 -S -triple dxil-pc-shadermodel6.3-library -S -emit-llvm -xhlsl -validator-version 1.1 -o - %s | FileCheck %s -// RUN: %clang -cc1 -S -triple spirv32 -S -emit-llvm -xhlsl -validator-version 1.1 -o - %s | FileCheck %s --check-prefix=NOT_DXIL + +// FIXME:The following line should work once SPIR-V support for HLSL is added. +// DISABLED: %clang -cc1 -S -triple spirv32 -S -emit-llvm -xhlsl -validator-version 1.1 -o - %s | FileCheck %s --check-prefix=NOT_DXIL // CHECK:!dx.valver = !{![[valver:[0-9]+]]} // CHECK:![[valver]] = !{i32 1, i32 1} diff --git a/clang/test/Driver/hlsl-lang-targets.hlsl b/clang/test/Driver/hlsl-lang-targets.hlsl new file mode 100644 --- /dev/null +++ b/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' diff --git a/clang/test/Preprocessor/predefined-macros-hlsl.hlsl b/clang/test/Preprocessor/predefined-macros-hlsl.hlsl --- a/clang/test/Preprocessor/predefined-macros-hlsl.hlsl +++ b/clang/test/Preprocessor/predefined-macros-hlsl.hlsl @@ -29,20 +29,20 @@ // PIXEL: #define __SHADER_TARGET_STAGE 0 // VERTEX: #define __SHADER_TARGET_STAGE 1 -// RUN: %clang_cc1 %s -E -dM -o - -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 - -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 - -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 - -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 - -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 - -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