From 67a83476b9a695213579a3e423946f32a7a0538d Mon Sep 17 00:00:00 2001 From: Greg Roth Date: Tue, 27 Aug 2024 15:37:32 -0600 Subject: [PATCH 1/3] Allow unsigned as a full type --- tools/clang/include/clang/Sema/DeclSpec.h | 6 ++--- tools/clang/lib/Sema/DeclSpec.cpp | 5 +--- .../clang/test/CodeGenHLSL/unsigned-int.hlsl | 27 +++++++++++++++++++ 3 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 tools/clang/test/CodeGenHLSL/unsigned-int.hlsl diff --git a/tools/clang/include/clang/Sema/DeclSpec.h b/tools/clang/include/clang/Sema/DeclSpec.h index cad7db16e9..7058f33cc7 100644 --- a/tools/clang/include/clang/Sema/DeclSpec.h +++ b/tools/clang/include/clang/Sema/DeclSpec.h @@ -619,9 +619,9 @@ class DeclSpec { /// \brief Return true if any type-specifier has been found. bool hasTypeSpecifier() const { return getTypeSpecType() != DeclSpec::TST_unspecified || - getTypeSpecWidth() != DeclSpec::TSW_unspecified || - getTypeSpecComplex() != DeclSpec::TSC_unspecified; - //getTypeSpecSign() != DeclSpec::TSS_unspecified; // HLSL Change - unsigned is not a complete type specifier. + getTypeSpecWidth() != DeclSpec::TSW_unspecified || + getTypeSpecComplex() != DeclSpec::TSC_unspecified || + getTypeSpecSign() != DeclSpec::TSS_unspecified; } /// \brief Return a bitmask of which flavors of specifiers this diff --git a/tools/clang/lib/Sema/DeclSpec.cpp b/tools/clang/lib/Sema/DeclSpec.cpp index 37c1554092..a0ef42f23a 100644 --- a/tools/clang/lib/Sema/DeclSpec.cpp +++ b/tools/clang/lib/Sema/DeclSpec.cpp @@ -1051,12 +1051,9 @@ void DeclSpec::Finish(DiagnosticsEngine &D, Preprocessor &PP, const PrintingPoli // signed/unsigned are only valid with int/char/wchar_t. if (TypeSpecSign != TSS_unspecified) { - // HLSL Change starts - signed/unsigned are not complete type specifiers. - #if 0 if (TypeSpecType == TST_unspecified) TypeSpecType = TST_int; - #endif - // shorthand vectors and matrices can have signed/unsigned specifiers. + // HLSL Change starts - shorthand vectors and matrices can have signed/unsigned specifiers. // If other typenames are used with signed/unsigned, it is already diagnosed by hlsl external source if (TypeSpecType != TST_int && TypeSpecType != TST_int128 && TypeSpecType != TST_char && TypeSpecType != TST_wchar && diff --git a/tools/clang/test/CodeGenHLSL/unsigned-int.hlsl b/tools/clang/test/CodeGenHLSL/unsigned-int.hlsl new file mode 100644 index 0000000000..8422ecb981 --- /dev/null +++ b/tools/clang/test/CodeGenHLSL/unsigned-int.hlsl @@ -0,0 +1,27 @@ +// RUN: %dxc -fcgl -T vs_6_0 %s | FileCheck %s + +// Test that unsigned alone is accepted and equivalent to an unsigned int + +// CHECK: @"\01?g_u@@3IB" = external constant i32, align 4 +unsigned g_u; + +// CHECK: @"\01?buf_u@@3V?$RWBuffer@I@@A" = external global %"class.RWBuffer", align 4 +// CHECK: @"\01?sbuf_u@@3V?$RWStructuredBuffer@I@@A" = external global %"class.RWStructuredBuffer", align 4 +RWBuffer buf_u; +RWStructuredBuffer sbuf_u; +RWByteAddressBuffer bab_u; + +unsigned doit(uint i, unsigned j); + +float4 main(unsigned VID : SV_VertexID, unsigned IID : SV_InstanceID) : SV_Position { + uint i = g_u; + // CHECK: %call = call i32 @"\01?doit@@YAIII@Z"(i32 %{{[0-9]+}}, i32 %{{[0-9]+}}) + buf_u[0] = doit(VID, i); + sbuf_u[0] = doit(IID, bab_u.Load(0)); + return doit(buf_u[1], sbuf_u[1]); +} + +// CHECK: define internal i32 @"\01?doit@@YAIII@Z"(i32 %i, i32 %j) +unsigned doit(uint i, unsigned j) { + return i + j; +} From 8b27043ce3da3a519ca292177e9479340c258630 Mon Sep 17 00:00:00 2001 From: Greg Roth Date: Wed, 28 Aug 2024 15:25:30 -0600 Subject: [PATCH 2/3] clang-format --- tools/clang/include/clang/Sema/DeclSpec.h | 8 ++++---- tools/clang/lib/Sema/DeclSpec.cpp | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tools/clang/include/clang/Sema/DeclSpec.h b/tools/clang/include/clang/Sema/DeclSpec.h index 7058f33cc7..5676510724 100644 --- a/tools/clang/include/clang/Sema/DeclSpec.h +++ b/tools/clang/include/clang/Sema/DeclSpec.h @@ -618,10 +618,10 @@ class DeclSpec { /// \brief Return true if any type-specifier has been found. bool hasTypeSpecifier() const { - return getTypeSpecType() != DeclSpec::TST_unspecified || - getTypeSpecWidth() != DeclSpec::TSW_unspecified || - getTypeSpecComplex() != DeclSpec::TSC_unspecified || - getTypeSpecSign() != DeclSpec::TSS_unspecified; + return getTypeSpecType() != DeclSpec::TST_unspecified || + getTypeSpecWidth() != DeclSpec::TSW_unspecified || + getTypeSpecComplex() != DeclSpec::TSC_unspecified || + getTypeSpecSign() != DeclSpec::TSS_unspecified; } /// \brief Return a bitmask of which flavors of specifiers this diff --git a/tools/clang/lib/Sema/DeclSpec.cpp b/tools/clang/lib/Sema/DeclSpec.cpp index a0ef42f23a..f77031a586 100644 --- a/tools/clang/lib/Sema/DeclSpec.cpp +++ b/tools/clang/lib/Sema/DeclSpec.cpp @@ -1053,8 +1053,9 @@ void DeclSpec::Finish(DiagnosticsEngine &D, Preprocessor &PP, const PrintingPoli if (TypeSpecSign != TSS_unspecified) { if (TypeSpecType == TST_unspecified) TypeSpecType = TST_int; - // HLSL Change starts - shorthand vectors and matrices can have signed/unsigned specifiers. - // If other typenames are used with signed/unsigned, it is already diagnosed by hlsl external source + // HLSL Change starts - shorthand vectors and matrices can have + // signed/unsigned specifiers. If other typenames are used with + // signed/unsigned, it is already diagnosed by hlsl external source if (TypeSpecType != TST_int && TypeSpecType != TST_int128 && TypeSpecType != TST_char && TypeSpecType != TST_wchar && TypeSpecType != TST_typename) { From a5a55c6427a393f84a7e27312d973127b4d6ed2e Mon Sep 17 00:00:00 2001 From: Greg Roth Date: Tue, 3 Sep 2024 01:51:53 -0600 Subject: [PATCH 3/3] Revert part of change --- tools/clang/include/clang/Sema/DeclSpec.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/clang/include/clang/Sema/DeclSpec.h b/tools/clang/include/clang/Sema/DeclSpec.h index 5676510724..cad7db16e9 100644 --- a/tools/clang/include/clang/Sema/DeclSpec.h +++ b/tools/clang/include/clang/Sema/DeclSpec.h @@ -618,10 +618,10 @@ class DeclSpec { /// \brief Return true if any type-specifier has been found. bool hasTypeSpecifier() const { - return getTypeSpecType() != DeclSpec::TST_unspecified || - getTypeSpecWidth() != DeclSpec::TSW_unspecified || - getTypeSpecComplex() != DeclSpec::TSC_unspecified || - getTypeSpecSign() != DeclSpec::TSS_unspecified; + return getTypeSpecType() != DeclSpec::TST_unspecified || + getTypeSpecWidth() != DeclSpec::TSW_unspecified || + getTypeSpecComplex() != DeclSpec::TSC_unspecified; + //getTypeSpecSign() != DeclSpec::TSS_unspecified; // HLSL Change - unsigned is not a complete type specifier. } /// \brief Return a bitmask of which flavors of specifiers this