Skip to content

Commit 4d62102

Browse files
authored
[HLSL] Warn about incomplete language support (#108894)
This adds a warning about incomplete language mode support before HLSL 202x. This is the last change in the sequence to fix and make HLSL 202x the default mode for Clang (#108044). Fixes #108044
1 parent 07045b5 commit 4d62102

File tree

5 files changed

+41
-7
lines changed

5 files changed

+41
-7
lines changed

clang/include/clang/Basic/DiagnosticFrontendKinds.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,4 +382,8 @@ def err_ast_action_on_llvm_ir : Error<
382382
def err_os_unsupport_riscv_fmv : Error<
383383
"function multiversioning is currently only supported on Linux">;
384384

385+
def warn_hlsl_langstd_minimal :
386+
Warning<"support for HLSL language version %0 is incomplete, "
387+
"recommend using %1 instead">,
388+
InGroup<HLSLDXCCompat>;
385389
}

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,6 +1549,9 @@ def DXILValidation : DiagGroup<"dxil-validation">;
15491549
// Warning for HLSL API availability
15501550
def HLSLAvailability : DiagGroup<"hlsl-availability">;
15511551

1552+
// Warnings specifically for DXC incompatabilities.
1553+
def HLSLDXCCompat : DiagGroup<"hlsl-dxc-compatability">;
1554+
15521555
// Warnings for legacy binding behavior
15531556
def LegacyConstantRegisterBinding : DiagGroup<"legacy-constant-register-binding">;
15541557

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4484,6 +4484,15 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
44844484
}
44854485
} else
44864486
Diags.Report(diag::err_drv_hlsl_unsupported_target) << T.str();
4487+
4488+
if (Opts.LangStd < LangStandard::lang_hlsl202x) {
4489+
const LangStandard &Requested =
4490+
LangStandard::getLangStandardForKind(Opts.LangStd);
4491+
const LangStandard &Recommended =
4492+
LangStandard::getLangStandardForKind(LangStandard::lang_hlsl202x);
4493+
Diags.Report(diag::warn_hlsl_langstd_minimal)
4494+
<< Requested.getName() << Recommended.getName();
4495+
}
44874496
}
44884497

44894498
return Diags.getNumErrors() == NumErrorsBefore;

clang/lib/Headers/hlsl.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,18 @@
99
#ifndef _HLSL_H_
1010
#define _HLSL_H_
1111

12+
#if defined(__clang__)
13+
// Don't warn about any of the DXC compatibility warnings in the clang-only
14+
// headers since these will never be used with DXC anyways.
15+
#pragma clang diagnostic push
16+
#pragma clang diagnostic ignored "-Whlsl-dxc-compatability"
17+
#endif
18+
1219
#include "hlsl/hlsl_basic_types.h"
1320
#include "hlsl/hlsl_intrinsics.h"
1421

22+
#if defined(__clang__)
23+
#pragma clang diagnostic pop
24+
#endif
25+
1526
#endif //_HLSL_H_

clang/test/Preprocessor/predefined-macros-hlsl.hlsl

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,30 @@
3434
// PIXEL: #define __SHADER_TARGET_STAGE 0
3535
// VERTEX: #define __SHADER_TARGET_STAGE 1
3636

37-
// 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
37+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library %s -E -dM -o - -x hlsl -std=hlsl2015 2>&1 | FileCheck -match-full-lines %s --check-prefixes=STD2015
38+
// STD2015: warning: support for HLSL language version hlsl2015 is incomplete, recommend using hlsl202x instead
3839
// STD2015: #define __HLSL_VERSION 2015
3940

40-
// 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
41+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library %s -E -dM -o - -x hlsl -std=hlsl2016 2>&1 | FileCheck -match-full-lines %s --check-prefixes=STD2016
42+
// STD2016: warning: support for HLSL language version hlsl2016 is incomplete, recommend using hlsl202x instead
4143
// STD2016: #define __HLSL_VERSION 2016
4244

43-
// 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
45+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library %s -E -dM -o - -x hlsl -std=hlsl2017 2>&1 | FileCheck -match-full-lines %s --check-prefixes=STD2017
46+
// STD2017: warning: support for HLSL language version hlsl2017 is incomplete, recommend using hlsl202x instead
4447
// STD2017: #define __HLSL_VERSION 2017
4548

46-
// 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
49+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library %s -E -dM -o - -x hlsl -std=hlsl2018 2>&1 | FileCheck -match-full-lines %s --check-prefixes=STD2018
50+
// STD2018: warning: support for HLSL language version hlsl2018 is incomplete, recommend using hlsl202x instead
4751
// STD2018: #define __HLSL_VERSION 2018
4852

49-
// 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
53+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library %s -E -dM -o - -x hlsl -std=hlsl2021 2>&1 | FileCheck -match-full-lines %s --check-prefixes=STD2021
54+
// STD2021: warning: support for HLSL language version hlsl2021 is incomplete, recommend using hlsl202x instead
5055
// STD2021: #define __HLSL_VERSION 2021
5156

52-
// 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
57+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library %s -E -dM -o - -x hlsl -std=hlsl202x | FileCheck -match-full-lines %s --check-prefixes=STD202x
58+
// STD202x-NOT: warning
5359
// STD202x: #define __HLSL_VERSION 2028
5460

55-
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library %s -E -dM -o - -x hlsl -std=hlsl202y | FileCheck -match-full-lines %s --check-prefixes=STD202y
61+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library %s -E -dM -o - -x hlsl -std=hlsl202y | FileCheck -match-full-lines %s --check-prefixes=STD202y
62+
// STD202y-NOT: warning
5663
// STD202y: #define __HLSL_VERSION 2029

0 commit comments

Comments
 (0)