Skip to content

Commit 2222e27

Browse files
authored
[HLSL] Add HLSL 202y language mode (#108437)
This change adds a new HLSL 202y language mode. Currently HLSL 202y is planned to add `auto` and `constexpr`. This change updates extension diagnostics to state that lambadas are a "clang HLSL" extension (since we have no planned release yet to include them), and that `auto` is a HLSL 202y extension when used in earlier language modes. Note: This PR does temporarily work around some differences between HLSL 2021 and 202x in Clang by changing test cases to explicitly specify 202x. A subsequent PR will update 2021's language flags to match 202x.
1 parent ebf25d9 commit 2222e27

16 files changed

+86
-38
lines changed

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1535,8 +1535,10 @@ def PedanticMacros : DiagGroup<"pedantic-macros",
15351535
def BranchProtection : DiagGroup<"branch-protection">;
15361536

15371537
// HLSL diagnostic groups
1538+
def HLSL202y : DiagGroup<"hlsl-202y-extensions">;
1539+
15381540
// Warnings for HLSL Clang extensions
1539-
def HLSLExtension : DiagGroup<"hlsl-extensions">;
1541+
def HLSLExtension : DiagGroup<"hlsl-extensions", [HLSL202y]>;
15401542

15411543
// Warning for mix packoffset and non-packoffset.
15421544
def HLSLMixPackOffset : DiagGroup<"mix-packoffset">;

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,10 @@ def err_expected_lambda_body : Error<"expected body of lambda expression">;
10731073
def warn_cxx98_compat_lambda : Warning<
10741074
"lambda expressions are incompatible with C++98">,
10751075
InGroup<CXX98Compat>, DefaultIgnore;
1076-
def ext_lambda : ExtWarn<"lambdas are a C++11 extension">, InGroup<CXX11>;
1076+
def ext_lambda : ExtWarn<"lambdas are a %select{C++11|clang HLSL}0 extension">,
1077+
InGroup<CXX11>;
1078+
def ext_hlsl_lambda : ExtWarn<ext_lambda.Summary>,
1079+
InGroup<HLSLExtension>;
10771080
def err_lambda_decl_specifier_repeated : Error<
10781081
"%select{'mutable'|'static'|'constexpr'|'consteval'}0 cannot "
10791082
"appear multiple times in a lambda declarator">;

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,10 @@ def err_invalid_width_spec : Error<
267267
def err_invalid_complex_spec : Error<"'_Complex %0' is invalid">;
268268

269269
def ext_auto_type_specifier : ExtWarn<
270-
"'auto' type specifier is a C++11 extension">, InGroup<CXX11>;
270+
"'auto' type specifier is a %select{C++11|HLSL 202y}0 extension">,
271+
InGroup<CXX11>;
272+
def ext_hlsl_auto_type_specifier : ExtWarn<
273+
ext_auto_type_specifier.Summary>, InGroup<HLSL202y>;
271274
def warn_auto_storage_class : Warning<
272275
"'auto' storage class specifier is redundant and incompatible with C++11">,
273276
InGroup<CXX11Compat>, DefaultIgnore;

clang/include/clang/Basic/LangOptions.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ class LangOptionsBase {
160160
HLSL_2017 = 2017,
161161
HLSL_2018 = 2018,
162162
HLSL_2021 = 2021,
163-
HLSL_202x = 2029,
163+
HLSL_202x = 2028,
164+
HLSL_202y = 2029,
164165
};
165166

166167
/// Clang versions with different platform ABI conformance.

clang/include/clang/Basic/LangStandards.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ LANGSTANDARD(hlsl202x, "hlsl202x",
256256
HLSL, "High Level Shader Language 202x",
257257
LineComment | HLSL | CPlusPlus | CPlusPlus11)
258258

259+
LANGSTANDARD(hlsl202y, "hlsl202y",
260+
HLSL, "High Level Shader Language 202y",
261+
LineComment | HLSL | CPlusPlus | CPlusPlus11)
262+
259263

260264
#undef LANGSTANDARD
261265
#undef LANGSTANDARD_ALIAS

clang/include/clang/Driver/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8914,7 +8914,7 @@ def dxc_hlsl_version : Option<["/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
89148914
Group<dxc_Group>,
89158915
Visibility<[DXCOption]>,
89168916
HelpText<"HLSL Version">,
8917-
Values<"2016, 2017, 2018, 2021, 202x">;
8917+
Values<"2016, 2017, 2018, 2021, 202x, 202y">;
89188918
def dxc_validator_path_EQ : Joined<["--"], "dxv-path=">, Group<dxc_Group>,
89198919
HelpText<"DXIL validator installation path">;
89208920
def dxc_disable_validation : DXCFlag<"Vd">,

clang/lib/Basic/LangOptions.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ void LangOptions::setLangDefaults(LangOptions &Opts, Language Lang,
159159
Opts.HLSLVersion = (unsigned)LangOptions::HLSL_2021;
160160
else if (LangStd == LangStandard::lang_hlsl202x)
161161
Opts.HLSLVersion = (unsigned)LangOptions::HLSL_202x;
162+
else if (LangStd == LangStandard::lang_hlsl202y)
163+
Opts.HLSLVersion = (unsigned)LangOptions::HLSL_202y;
162164

163165
// OpenCL has some additional defaults.
164166
if (Opts.OpenCL) {

clang/lib/Basic/LangStandards.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ LangStandard::Kind LangStandard::getHLSLLangKind(StringRef Name) {
7878
.Case("2018", LangStandard::lang_hlsl2018)
7979
.Case("2021", LangStandard::lang_hlsl2021)
8080
.Case("202x", LangStandard::lang_hlsl202x)
81+
.Case("202y", LangStandard::lang_hlsl202y)
8182
.Default(LangStandard::lang_unspecified);
8283
}
8384

clang/lib/Parse/ParseExprCXX.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,9 +1344,13 @@ static void DiagnoseStaticSpecifierRestrictions(Parser &P,
13441344
ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
13451345
LambdaIntroducer &Intro) {
13461346
SourceLocation LambdaBeginLoc = Intro.Range.getBegin();
1347-
Diag(LambdaBeginLoc, getLangOpts().CPlusPlus11
1348-
? diag::warn_cxx98_compat_lambda
1349-
: diag::ext_lambda);
1347+
if (getLangOpts().HLSL)
1348+
Diag(LambdaBeginLoc, diag::ext_hlsl_lambda) << /*HLSL*/ 1;
1349+
else
1350+
Diag(LambdaBeginLoc, getLangOpts().CPlusPlus11
1351+
? diag::warn_cxx98_compat_lambda
1352+
: diag::ext_lambda)
1353+
<< /*C++*/ 0;
13501354

13511355
PrettyStackTraceLoc CrashInfo(PP.getSourceManager(), LambdaBeginLoc,
13521356
"lambda expression parsing");

clang/lib/Sema/DeclSpec.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,11 @@ void DeclSpec::Finish(Sema &S, const PrintingPolicy &Policy) {
14181418
// specifier in a pre-C++11 dialect of C++ or in a pre-C23 dialect of C.
14191419
if (!S.getLangOpts().CPlusPlus11 && !S.getLangOpts().C23 &&
14201420
TypeSpecType == TST_auto)
1421-
S.Diag(TSTLoc, diag::ext_auto_type_specifier);
1421+
S.Diag(TSTLoc, diag::ext_auto_type_specifier) << /*C++*/ 0;
1422+
if (S.getLangOpts().HLSL &&
1423+
S.getLangOpts().getHLSLVersion() < LangOptions::HLSL_202y &&
1424+
TypeSpecType == TST_auto)
1425+
S.Diag(TSTLoc, diag::ext_hlsl_auto_type_specifier) << /*HLSL*/ 1;
14221426
if (S.getLangOpts().CPlusPlus && !S.getLangOpts().CPlusPlus11 &&
14231427
StorageClassSpec == SCS_auto)
14241428
S.Diag(StorageClassSpecLoc, diag::warn_auto_storage_class)

0 commit comments

Comments
 (0)