Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion tools/clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10459,7 +10459,11 @@ ParmVarDecl *Sema::CheckParameter(DeclContext *DC, SourceLocation StartLoc,
if (T.getAddressSpace() != 0) {
// OpenCL allows function arguments declared to be an array of a type
// to be qualified with an address space.
if (!(getLangOpts().OpenCL && T->isArrayType())) {
if (!(getLangOpts().OpenCL && T->isArrayType()) &&
// HLSL allows parameters to be qualified with the groupshared
// address space.
!(getLangOpts().HLSL &&
T.getAddressSpace() == hlsl::DXIL::kTGSMAddrSpace)) {
Diag(NameLoc, diag::err_arg_with_address_space);
New->setInvalidDecl();
}
Expand Down
11 changes: 11 additions & 0 deletions tools/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,17 @@ void Sema::InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs,
continue;
}

if (isa<HLSLGroupSharedAttr>(TmplAttr)) {
// the type wasn't set properly before so we need to instantiate this type
// as a groupshared reference
ParmVarDecl *NewParm = cast<ParmVarDecl>(New);
NewParm->addAttr(TmplAttr->clone(getASTContext()));
NewParm->setType(Context.getAddrSpaceQualType(
NewParm->getType(), hlsl::DXIL::kTGSMAddrSpace));
NewParm->setType(Context.getLValueReferenceType(NewParm->getType()));
continue;
}

// HLSL Change Begin - Validate post-instantiation attributes
DiagnoseHLSLDeclAttr(New, TmplAttr);
// HLSL Change End
Expand Down
12 changes: 12 additions & 0 deletions tools/clang/test/CodeGenHLSL/groupsharedArgs/TemplateTest.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,19 @@ void fn1(groupshared Shared<int> Sh) {
Sh.Arr[1] = D;
}

// CHECK-LABEL: <4 x i32> @"\01??$tfoo@V?$vector@H$03@@@@YA?AV?$vector@H$03@@AGAV0@@Z"(<4 x i32> addrspace(3)* dereferenceable(16) %a)
// CHECK: [[B:%.*]] = load <4 x i32>, <4 x i32> addrspace(3)* %a, align 4
// CHECK: ret <4 x i32> [[B]]
template<typename T>
T tfoo(groupshared T a) {
return a;
}

groupshared int4 SharedData1;

[numthreads(4, 1, 1)]
void main(uint3 TID : SV_GroupThreadID) {
fn1(SharedData);
tfoo<int4>(SharedData1);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we expect something like tfoo<uint4>(SharedData1) to be valid?

edit: I see we don't allow uint16_t to half below

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah casting isn't allowed.

tfoo(SharedData1);
}
9 changes: 9 additions & 0 deletions tools/clang/test/SemaHLSL/v202x/groupshared/ExplicitCast.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,16 @@ void fn1(groupshared half Sh) {
Sh = 5;
}

template<typename T>
T fnT(groupshared T A) {
// expected-note@-1{{candidate function [with T = half] not viable: 1st argument ('half') is in address space 0, but parameter must be in address space 3}}
return A;
}

void fn2() {
fn1((half)SharedData);
// expected-error@-1{{no matching function for call to 'fn1'}}
// not sure why someone would write this but make sure templates do something sane.
fnT<half>((half)SharedData);
// expected-error@-1{{no matching function for call to 'fnT'}}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,14 @@ export void fn1(groupshared uint Sh) {
// expected-error@-1{{groupshared and export/noinline cannot be used together for a parameter}}
Sh = 6;
}

template<typename T>
void fn3(groupshared T A, groupshared T B) {
A = B;
}

export template void fn3<uint>(groupshared uint A, groupshared uint B);
// expected-error@-1{{'template' is a reserved keyword in HLSL}}
template [noinline] void fn3<float>(groupshared float A, groupshared float B);
// expected-error@-1{{use of undeclared identifier 'noinline'}}
// expected-error@-2{{expected unqualified-id}}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: file ending

16 changes: 16 additions & 0 deletions tools/clang/test/SemaHLSL/v202x/groupshared/InOut.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,19 @@ void fn8() {
fn1(SharedData);
// expected-warning@-1{{Passing groupshared variable to a parameter annotated with inout. See 'groupshared' parameter annotation added in 202x}}
}

template<typename T>
T fn9(inout groupshared T A) {
// expected-error@-1{{'inout' and 'groupshared' cannot be used together for a parameter}}
return A;
}
template<typename T>
T fn10(in groupshared T A) {
// expected-error@-1{{'in' and 'groupshared' cannot be used together for a parameter}}
return A;
}
template<typename T>
T fn11(out groupshared T A) {
// expected-error@-1{{'out' and 'groupshared' cannot be used together for a parameter}}
return A;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@ void fn1(groupshared half Sh) {
Sh = 5;
}

template<typename T>
T fn2(groupshared T Sh) {
// expected-note@-1{{candidate template ignored: can't deduce a type for 'T' that would make '__attribute__((address_space(3))) T' equal 'half'}}
return Sh;
}

[numthreads(4, 1, 1)]
void main(uint3 TID : SV_GroupThreadID) {
half tmp = 1.0;
fn1(tmp);
// expected-error@-1{{no matching function for call to 'fn1'}}
fn2(tmp);
// expected-error@-1{{no matching function for call to 'fn2'}}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ void fn1(groupshared uint Sh) {
void fn2() {
fn1(SharedData);
}

template<typename T>
T fn3(groupshared T A) {
// expected-warning@-1{{Support for groupshared parameter annotation not added until HLSL 202x}}
return A;
}
8 changes: 8 additions & 0 deletions tools/clang/test/SemaHLSL/v202x/groupshared/ScalarTest.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ void fn1(groupshared half Sh) {
Sh = 5;
}

template<typename T>
T fn3(groupshared T A) {
// expected-note@-1{{candidate function [with T = half] not viable: no known conversion from '__attribute__((address_space(3))) uint16_t' to '__attribute__((address_space(3))) half' for 1st argument}}
return A;
}

void fn2() {
fn1(SharedData);
// expected-error@-1{{no matching function for call to 'fn1'}}
fn3<half>(SharedData);
// expected-error@-1{{no matching function for call to 'fn3'}}
}