Skip to content

Commit

Permalink
[HLSL] Align language modes on 202x as default (llvm#108662)
Browse files Browse the repository at this point in the history
As captured in issue llvm#108044, HLSL 202x is the target language mode for
conformance for Clang. Earlier language modes will be a best effort and
prioritized after 2020x. To make this easier and reduce our testing
complexity we want to make 202x the default language mode now, and align
all earlier modes to match 202x (except where we explicitly deviate).

This change has the following concrete changes:
* All older language modes gain `CPlusPlus11` as a base
* The default language mode for HLSL sources is changed to 202x
* A few test cases are updated to resolve differences in generated
diagnostics.

Second to last change for  llvm#108044
  • Loading branch information
llvm-beanz committed Sep 16, 2024
1 parent dbc5900 commit 4886403
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 18 deletions.
12 changes: 6 additions & 6 deletions clang/include/clang/Basic/LangStandards.def
Original file line number Diff line number Diff line change
Expand Up @@ -230,27 +230,27 @@ LANGSTANDARD_ALIAS_DEPR(openclcpp2021, "CLC++2021")
// HLSL
LANGSTANDARD(hlsl, "hlsl",
HLSL, "High Level Shader Language",
LineComment | HLSL | CPlusPlus )
LineComment | HLSL | CPlusPlus | CPlusPlus11)

LANGSTANDARD(hlsl2015, "hlsl2015",
HLSL, "High Level Shader Language 2015",
LineComment | HLSL | CPlusPlus )
LineComment | HLSL | CPlusPlus | CPlusPlus11)

LANGSTANDARD(hlsl2016, "hlsl2016",
HLSL, "High Level Shader Language 2016",
LineComment | HLSL | CPlusPlus )
LineComment | HLSL | CPlusPlus | CPlusPlus11)

LANGSTANDARD(hlsl2017, "hlsl2017",
HLSL, "High Level Shader Language 2017",
LineComment | HLSL | CPlusPlus )
LineComment | HLSL | CPlusPlus | CPlusPlus11)

LANGSTANDARD(hlsl2018, "hlsl2018",
HLSL, "High Level Shader Language 2018",
LineComment | HLSL | CPlusPlus )
LineComment | HLSL | CPlusPlus | CPlusPlus11)

LANGSTANDARD(hlsl2021, "hlsl2021",
HLSL, "High Level Shader Language 2021",
LineComment | HLSL | CPlusPlus )
LineComment | HLSL | CPlusPlus | CPlusPlus11)

LANGSTANDARD(hlsl202x, "hlsl202x",
HLSL, "High Level Shader Language 202x",
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Basic/LangStandards.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ LangStandard::Kind clang::getDefaultLanguageStandard(clang::Language Lang,
case Language::RenderScript:
return LangStandard::lang_c99;
case Language::HLSL:
return LangStandard::lang_hlsl2021;
return LangStandard::lang_hlsl202x;
}
llvm_unreachable("unhandled Language kind!");
}
2 changes: 1 addition & 1 deletion clang/test/Preprocessor/predefined-macros-hlsl.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// HALF: #define __HLSL_ENABLE_16_BIT 1
// NOHALF-NOT: __HLSL_ENABLE_16_BIT

// CHECK: #define __HLSL_VERSION 2021
// CHECK: #define __HLSL_VERSION 2028

// CHECK: #define __SHADER_STAGE_AMPLIFICATION 14
// CHECK: #define __SHADER_STAGE_COMPUTE 5
Expand Down
2 changes: 1 addition & 1 deletion clang/test/SemaHLSL/BuiltIns/RWBuffers.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ RWBuffer<> BufferErr2;

[numthreads(1,1,1)]
void main() {
(void)Buffer.h; // expected-error {{'h' is a private member of 'hlsl::RWBuffer<vector<float, 3> >'}}
(void)Buffer.h; // expected-error {{'h' is a private member of 'hlsl::RWBuffer<vector<float, 3>>'}}
// expected-note@* {{implicitly declared private here}}
}
2 changes: 1 addition & 1 deletion clang/test/SemaHLSL/BuiltIns/StructuredBuffers.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ StructuredBuffer<> BufferErr2;

[numthreads(1,1,1)]
void main() {
(void)Buffer.h; // expected-error {{'h' is a private member of 'hlsl::StructuredBuffer<vector<float, 3> >'}}
(void)Buffer.h; // expected-error {{'h' is a private member of 'hlsl::StructuredBuffer<vector<float, 3>>'}}
// expected-note@* {{implicitly declared private here}}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ _Static_assert(is_same<__decltype(4294967296), int64_t>::value, "4294967296 is i
// Clang emits a warning that it is interpreting it as unsigned because that is
// not conforming to the C standard.

// expected-warning@+1{{integer literal is too large to be represented in type 'long' and is subject to undefined behavior under C++98, interpreting as 'unsigned long'; this literal will be ill-formed in C++11 onwards}}
// expected-warning@+1{{integer literal is too large to be represented in a signed integer type, interpreting as unsigned}}
static const uint64_t V = 9223372036854775808;

_Static_assert(is_same<__decltype(0x0), int>::value, "0x0 is int");
Expand Down
3 changes: 2 additions & 1 deletion clang/test/SemaHLSL/Types/Traits/IsIntangibleTypeErrors.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
struct Undefined; // expected-note {{forward declaration of 'Undefined'}}
_Static_assert(!__builtin_hlsl_is_intangible(Undefined), ""); // expected-error{{incomplete type 'Undefined' used in type trait expression}}

void fn(int X) {
void fn(int X) { // expected-note {{declared here}}
// expected-error@#vla {{variable length arrays are not supported for the current target}}
// expected-error@#vla {{variable length arrays are not supported in '__builtin_hlsl_is_intangible'}}
// expected-warning@#vla {{variable length arrays in C++ are a Clang extension}}
// expected-note@#vla {{function parameter 'X' with unknown value cannot be used in a constant expression}}
_Static_assert(!__builtin_hlsl_is_intangible(int[X]), ""); // #vla
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.6-library -finclude-default-header -verify %s
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.6-library -finclude-default-header -verify %s

// Some things that don't work!

Expand All @@ -14,11 +14,12 @@ _Static_assert(__builtin_hlsl_is_scalarized_layout_compatible(Undefined, Defined

// Case 2: No variable length arrays!

void fn(int X) {
void fn(int X) { // expected-note{{declared here}}
// expected-error@#vla {{variable length arrays are not supported for the current target}}
// expected-error@#vla {{variable length arrays are not supported in '__builtin_hlsl_is_scalarized_layout_compatible'}}
// expected-error@#vla {{static assertion failed due to requirement '__builtin_hlsl_is_scalarized_layout_compatible(int[4], int[X])'}}
// expected-warning@#vla {{variable length arrays in C++ are a Clang extension}}
// expected-note@#vla{{function parameter 'X' with unknown value cannot be used in a constant expression}}
_Static_assert(__builtin_hlsl_is_scalarized_layout_compatible(int[4], int[X]), ""); // #vla
}

Expand Down
4 changes: 1 addition & 3 deletions clang/test/SemaHLSL/group_shared.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ template<typename T>
T tfoo(T t) {
return t;
}
// expected-warning@+1 {{alias declarations are a C++11 extension}}
using GSF = groupshared float;
GSF gs;
// expected-error@+1 {{no matching function for call to 'tfoo'}}
Expand All @@ -73,8 +72,7 @@ groupshared void (*fp)();
void (*fp2)(groupshared float);
// NOTE: HLSL not support trailing return types.
// expected-warning@#func{{'auto' type specifier is a HLSL 202y extension}}
// expected-warning@#func {{'auto' type specifier is a C++11 extension}}
// expected-error@#func {{expected function body after function declarator}}
// expected-error@#func{{return type cannot be qualified with address space}}
auto func() -> groupshared void; // #func
// expected-warning@+2 {{'groupshared' attribute only applies to variables}}
// expected-error@+1 {{return type cannot be qualified with address space}}
Expand Down
1 change: 0 additions & 1 deletion clang/test/SemaHLSL/prohibit_reference.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
int& bark(int); // expected-error {{references are unsupported in HLSL}}
void meow(int&); // expected-error {{references are unsupported in HLSL}}
void chirp(int &&); // expected-error {{references are unsupported in HLSL}}
// expected-warning@-1 {{rvalue references are a C++11 extension}}

struct Foo {
int X;
Expand Down

0 comments on commit 4886403

Please sign in to comment.