From 488640389faedee8c65566275441779faa620fd2 Mon Sep 17 00:00:00 2001 From: Chris B Date: Mon, 16 Sep 2024 17:17:15 -0500 Subject: [PATCH] [HLSL] Align language modes on 202x as default (#108662) As captured in issue #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 #108044 --- clang/include/clang/Basic/LangStandards.def | 12 ++++++------ clang/lib/Basic/LangStandards.cpp | 2 +- clang/test/Preprocessor/predefined-macros-hlsl.hlsl | 2 +- clang/test/SemaHLSL/BuiltIns/RWBuffers.hlsl | 2 +- clang/test/SemaHLSL/BuiltIns/StructuredBuffers.hlsl | 2 +- .../Types/Arithmetic/literal_suffixes_202x.hlsl | 2 +- .../Types/Traits/IsIntangibleTypeErrors.hlsl | 3 ++- .../Traits/ScalarizedLayoutCompatibleErrors.hlsl | 5 +++-- clang/test/SemaHLSL/group_shared.hlsl | 4 +--- clang/test/SemaHLSL/prohibit_reference.hlsl | 1 - 10 files changed, 17 insertions(+), 18 deletions(-) diff --git a/clang/include/clang/Basic/LangStandards.def b/clang/include/clang/Basic/LangStandards.def index 41e756d9365dcf..982a79873adb59 100644 --- a/clang/include/clang/Basic/LangStandards.def +++ b/clang/include/clang/Basic/LangStandards.def @@ -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", diff --git a/clang/lib/Basic/LangStandards.cpp b/clang/lib/Basic/LangStandards.cpp index b9b914b0adc772..214567a53efe95 100644 --- a/clang/lib/Basic/LangStandards.cpp +++ b/clang/lib/Basic/LangStandards.cpp @@ -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!"); } diff --git a/clang/test/Preprocessor/predefined-macros-hlsl.hlsl b/clang/test/Preprocessor/predefined-macros-hlsl.hlsl index bc3779e4129f0d..93a8455fd673b2 100644 --- a/clang/test/Preprocessor/predefined-macros-hlsl.hlsl +++ b/clang/test/Preprocessor/predefined-macros-hlsl.hlsl @@ -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 diff --git a/clang/test/SemaHLSL/BuiltIns/RWBuffers.hlsl b/clang/test/SemaHLSL/BuiltIns/RWBuffers.hlsl index 774309c714f657..76b5d01b8036eb 100644 --- a/clang/test/SemaHLSL/BuiltIns/RWBuffers.hlsl +++ b/clang/test/SemaHLSL/BuiltIns/RWBuffers.hlsl @@ -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 >'}} + (void)Buffer.h; // expected-error {{'h' is a private member of 'hlsl::RWBuffer>'}} // expected-note@* {{implicitly declared private here}} } diff --git a/clang/test/SemaHLSL/BuiltIns/StructuredBuffers.hlsl b/clang/test/SemaHLSL/BuiltIns/StructuredBuffers.hlsl index 2450941f5d9b46..a472d5519dc51f 100644 --- a/clang/test/SemaHLSL/BuiltIns/StructuredBuffers.hlsl +++ b/clang/test/SemaHLSL/BuiltIns/StructuredBuffers.hlsl @@ -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 >'}} + (void)Buffer.h; // expected-error {{'h' is a private member of 'hlsl::StructuredBuffer>'}} // expected-note@* {{implicitly declared private here}} } diff --git a/clang/test/SemaHLSL/Types/Arithmetic/literal_suffixes_202x.hlsl b/clang/test/SemaHLSL/Types/Arithmetic/literal_suffixes_202x.hlsl index 2aeb4047565d6a..95f08463f55efe 100644 --- a/clang/test/SemaHLSL/Types/Arithmetic/literal_suffixes_202x.hlsl +++ b/clang/test/SemaHLSL/Types/Arithmetic/literal_suffixes_202x.hlsl @@ -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"); diff --git a/clang/test/SemaHLSL/Types/Traits/IsIntangibleTypeErrors.hlsl b/clang/test/SemaHLSL/Types/Traits/IsIntangibleTypeErrors.hlsl index 0803086749bd7d..de9ac90b895fc6 100644 --- a/clang/test/SemaHLSL/Types/Traits/IsIntangibleTypeErrors.hlsl +++ b/clang/test/SemaHLSL/Types/Traits/IsIntangibleTypeErrors.hlsl @@ -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 } diff --git a/clang/test/SemaHLSL/Types/Traits/ScalarizedLayoutCompatibleErrors.hlsl b/clang/test/SemaHLSL/Types/Traits/ScalarizedLayoutCompatibleErrors.hlsl index 4c96795da7fd0c..85c6580d052de9 100644 --- a/clang/test/SemaHLSL/Types/Traits/ScalarizedLayoutCompatibleErrors.hlsl +++ b/clang/test/SemaHLSL/Types/Traits/ScalarizedLayoutCompatibleErrors.hlsl @@ -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! @@ -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 } diff --git a/clang/test/SemaHLSL/group_shared.hlsl b/clang/test/SemaHLSL/group_shared.hlsl index b51114700b041d..0293ddd15eeb94 100644 --- a/clang/test/SemaHLSL/group_shared.hlsl +++ b/clang/test/SemaHLSL/group_shared.hlsl @@ -58,7 +58,6 @@ template 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'}} @@ -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}} diff --git a/clang/test/SemaHLSL/prohibit_reference.hlsl b/clang/test/SemaHLSL/prohibit_reference.hlsl index 6e76cfa1422381..11ee9b20cf5544 100644 --- a/clang/test/SemaHLSL/prohibit_reference.hlsl +++ b/clang/test/SemaHLSL/prohibit_reference.hlsl @@ -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;