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)

clang/test/ParserHLSL/group_shared.hlsl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -o - -fsyntax-only %s -verify
1+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -std=hlsl202x -o - -fsyntax-only %s -verify
22
extern groupshared float f;
33
extern float groupshared f; // Ok, redeclaration?
44

55

6-
// expected-warning@+3 {{lambdas are a C++11 extension}}
7-
// expected-error@+2 {{expected body of lambda expression}}
8-
// expected-warning@+1 {{'auto' type specifier is a C++11 extension}}
9-
auto l = []() groupshared {};
6+
// expected-warning@#gs_lambda {{lambdas are a clang HLSL extension}}
7+
// expected-error@#gs_lambda {{expected body of lambda expression}}
8+
// expected-warning@#gs_lambda {{'auto' type specifier is a HLSL 202y extension}}
9+
auto l = []() groupshared {}; // #gs_lambda
1010

1111
float groupshared [[]] i = 12;
1212

clang/test/ParserHLSL/group_shared_202x.hlsl

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
extern groupshared float f;
33
extern float groupshared f; // Ok, redeclaration?
44

5-
// expected-error@+1 {{return type cannot be qualified with address space}}
6-
auto l = []() -> groupshared void {};
7-
// expected-error@+1 {{expected a type}}
8-
auto l2 = []() -> groupshared {};
5+
// expected-error@#l {{return type cannot be qualified with address space}}
6+
// expected-warning@#l {{lambdas are a clang HLSL extension}}
7+
// expected-warning@#l{{'auto' type specifier is a HLSL 202y extension}}
8+
auto l = []() -> groupshared void {}; // #l
9+
// expected-error@#l2 {{expected a type}}
10+
// expected-warning@#l2 {{lambdas are a clang HLSL extension}}
11+
// expected-warning@#l2{{'auto' type specifier is a HLSL 202y extension}}
12+
auto l2 = []() -> groupshared {}; // #l2
913

1014
float groupshared [[]] i = 12;
1115

@@ -17,13 +21,19 @@ void foo() {
1721

1822
extern groupshared float f;
1923
const float cf = f;
20-
// expected-error@+1 {{'auto' return without trailing return type; deduced return types are a C++14 extension}}
21-
auto func() {
24+
// expected-error@#func{{'auto' return without trailing return type; deduced return types are a C++14 extension}}
25+
// expected-warning@#func{{'auto' type specifier is a HLSL 202y extension}}
26+
auto func() { // #func
2227
return f;
2328
}
2429

2530
void other() {
26-
// NOTE: groupshared and const are stripped off thanks to lvalue to rvalue conversions and we deduce float for the return type.
27-
auto l = [&]() { return f; };
28-
auto l2 = [&]() { return cf; };
31+
// NOTE: groupshared and const are stripped off thanks to lvalue to rvalue
32+
// conversions and we deduce float for the return type.
33+
// expected-warning@#local{{lambdas are a clang HLSL extension}}
34+
// expected-warning@#local{{'auto' type specifier is a HLSL 202y extension}}
35+
auto l = [&]() { return f; }; // #local
36+
// expected-warning@#local2{{lambdas are a clang HLSL extension}}
37+
// expected-warning@#local2{{'auto' type specifier is a HLSL 202y extension}}
38+
auto l2 = [&]() { return cf; }; // #local2
2939
}

clang/test/ParserHLSL/invalid_inside_cb.hlsl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -o - -fsyntax-only %s -verify
1+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -std=hlsl202x -o - -fsyntax-only %s -verify
22

33
// template not allowed inside cbuffer.
44
cbuffer A {
@@ -15,7 +15,6 @@ cbuffer A {
1515

1616
// typealias not allowed inside cbuffer.
1717
cbuffer A {
18-
// expected-error@+2 {{invalid declaration inside cbuffer}}
19-
// expected-warning@+1 {{alias declarations are a C++11 extension}}
18+
// expected-error@+1 {{invalid declaration inside cbuffer}}
2019
using F32 = float;
2120
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,7 @@
5050
// STD2021: #define __HLSL_VERSION 2021
5151

5252
// 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
53-
// STD202x: #define __HLSL_VERSION 2029
53+
// STD202x: #define __HLSL_VERSION 2028
54+
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
56+
// STD202y: #define __HLSL_VERSION 2029

clang/test/SemaHLSL/group_shared.hlsl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,10 @@ groupshared void (*fp)();
7272
// expected-error@+1 {{parameter may not be qualified with an address space}}
7373
void (*fp2)(groupshared float);
7474
// NOTE: HLSL not support trailing return types.
75-
// expected-warning@+2 {{'auto' type specifier is a C++11 extension}}
76-
// expected-error@+1 {{expected function body after function declarator}}
77-
auto func() -> groupshared void;
75+
// expected-warning@#func{{'auto' type specifier is a HLSL 202y extension}}
76+
// expected-warning@#func {{'auto' type specifier is a C++11 extension}}
77+
// expected-error@#func {{expected function body after function declarator}}
78+
auto func() -> groupshared void; // #func
7879
// expected-warning@+2 {{'groupshared' attribute only applies to variables}}
7980
// expected-error@+1 {{return type cannot be qualified with address space}}
8081
void groupshared f();

clang/test/SemaHLSL/group_shared_202x.hlsl

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
11
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -std=hlsl202x -o - -fsyntax-only %s -verify
2+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -std=hlsl202y -o - -fsyntax-only %s -verify
23

3-
// expected-error@+1 {{return type cannot be qualified with address space}}
4-
auto func() -> groupshared void;
4+
#if __HLSL_VERSION < 2029
5+
// expected-warning@#func{{'auto' type specifier is a HLSL 202y extension}}
6+
// expected-warning@#func_gs{{'auto' type specifier is a HLSL 202y extension}}
7+
// expected-warning@#l{{'auto' type specifier is a HLSL 202y extension}}
8+
// expected-warning@#l2{{'auto' type specifier is a HLSL 202y extension}}
9+
#endif
510

6-
// expected-error@+1 {{parameter may not be qualified with an address space}}
7-
auto func(float groupshared) -> void;
11+
// expected-error@#func {{return type cannot be qualified with address space}}
12+
auto func() -> groupshared void; // #func
813

9-
// expected-error@+1 {{parameter may not be qualified with an address space}}
10-
auto l = [](groupshared float ) {};
14+
// expected-error@#func_gs {{parameter may not be qualified with an address space}}
15+
auto func(float groupshared) -> void; // #func_gs
1116

12-
// expected-error@+1 {{return type cannot be qualified with address space}}
13-
auto l2 = []() -> groupshared void {};
17+
18+
// expected-error@#l {{parameter may not be qualified with an address space}}
19+
// expected-warning@#l {{lambdas are a clang HLSL extension}}
20+
auto l = [](groupshared float ) {}; // #l
21+
22+
// expected-error@#l2 {{return type cannot be qualified with address space}}
23+
// expected-warning@#l2 {{lambdas are a clang HLSL extension}}
24+
auto l2 = []() -> groupshared void {}; // #l2
1425

1526
struct S {
1627
// expected-error@+1 {{return type cannot be qualified with address space}}

0 commit comments

Comments
 (0)