Skip to content

Commit 4978538

Browse files
danbrown-amdsam-delr
authored andcommitted
Allow HLSLDecls in dependent DeclContexts (#4114)
Summary of the changes: - Error for dependent context decl (template decl) now only occurs when templates are not enabled - Amended faulty test cases revealed by bug fix (tools\clang\test\HLSLFileCheck\hlsl\payload_qualifier\combination.hlsl, tools\clang\test\HLSLFileCheck\hlsl\template\InstantiateHLSLAttributes.hlsl, tools\clang\test\HLSLFileCheck\hlsl\template\missing_typename.hlsl) - Added test case to reflect bug fix (tools\clang\test\HLSLFileCheck\hlsl\template\3731-resource-descriptor-heap.hlsl) Attribution: Chris Bieneman Timothy Corringham Samantha Del Rosario Co-authored-by: sam-sam98 <[email protected]>
1 parent dc401d9 commit 4978538

5 files changed

Lines changed: 52 additions & 229 deletions

File tree

tools/clang/lib/Sema/SemaHLSL.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12425,12 +12425,11 @@ bool Sema::DiagnoseHLSLDecl(Declarator &D, DeclContext *DC, Expr *BitWidth,
1242512425
assert(getLangOpts().HLSL &&
1242612426
"otherwise this is called without checking language first");
1242712427

12428-
// NOTE: some tests may declare templates.
12429-
if (DC->isDependentContext()) return true;
12428+
// If we have a template declaration but haven't enabled templates, error.
12429+
if (DC->isDependentContext() && !getLangOpts().EnableTemplates) return false;
1243012430

1243112431
DeclSpec::SCS storage = D.getDeclSpec().getStorageClassSpec();
1243212432
assert(!DC->isClosure() && "otherwise parser accepted closure syntax instead of failing with a syntax error");
12433-
assert(!DC->isDependentContext() && "otherwise parser accepted a template instead of failing with a syntax error");
1243412433

1243512434
bool result = true;
1243612435
bool isTypedef = storage == DeclSpec::SCS_typedef;

tools/clang/test/HLSLFileCheck/hlsl/payload_qualifier/combination.hlsl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %dxc -T lib_6_6 %s -enable-payload-qualifiers | FileCheck %s
2+
// RUN: %dxc -T lib_6_6 %s -enable-payload-qualifiers -enable-templates -DTEMPLATES | FileCheck %s
23

34
// CHECK: error: field 'x1' is qualified 'read' for shader stage 'miss' but has no valid producer
45
// CHECK: error: field 'x2' is qualified 'read' for shader stage 'closesthit' but has no valid producer
@@ -247,9 +248,15 @@
247248
// CHECK: error: field 'x246' is qualified 'write' for shader stage 'miss' but has no valid consumer
248249
// CHECK: error: field 'x246' is qualified 'write' for shader stage 'closesthit' but has no valid consumer
249250
// CHECK: error: field 'x247' is qualified 'write' for shader stage 'miss' but has no valid consumer
250-
// CHECK: error: field 'x247' is qualified 'write' for shader stage 'closesthit' but has no valid consumer
251+
// CHECK: error: field 'x247' is qualified 'write' for shader stage 'closesthit'
252+
// but has no valid consumer
253+
#ifdef TEMPLATES
254+
template<typename I>
255+
#else
256+
#define I int
257+
#endif
251258
struct [payload] MyPayload {
252-
int x0 : read();
259+
I x0 : read();
253260
int x1 : read(miss);
254261
int x2 : read(closesthit);
255262
int x3 : read(miss, closesthit);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: %dxc -T cs_6_6 -E main -enable-templates -ast-dump %s | FileCheck %s
2+
// RUN: %dxc -T cs_6_6 -E main -HV 2021 -ast-dump %s | FileCheck %s
3+
4+
struct SimpleBuffer {
5+
uint handle;
6+
7+
template<typename T>
8+
T Load() {
9+
ByteAddressBuffer buf = ResourceDescriptorHeap[handle];
10+
return buf.Load<T>(0);
11+
}
12+
};
13+
14+
[numthreads(1,1,1)]
15+
void main() {
16+
SimpleBuffer b = (SimpleBuffer)0;
17+
b.Load<uint>();
18+
}
19+
20+
// CHECK: CXXOperatorCallExpr 0x{{[0-9a-fA-F]+}} <col:29, col:58> 'const .Resource'
21+
// CHECK-NEXT: ImplicitCastExpr 0x{{[0-9a-fA-F]+}} <col:51, col:58> 'const .Resource (*)(unsigned int) const' <FunctionToPointerDecay>
22+
// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-fA-F]+}} <col:51, col:58> 'const .Resource (unsigned int) const' lvalue CXXMethod 0x{{[0-9a-fA-F]+}} 'operator[]' 'const .Resource (unsigned int) const'
23+
// CHECK-NEXT: ImplicitCastExpr 0x{{[0-9a-fA-F]+}} <col:29> 'const .Resource' lvalue <NoOp>
24+
// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-fA-F]+}} <col:29> '.Resource' lvalue Var 0x{{[0-9a-fA-F]+}} 'ResourceDescriptorHeap' '.Resource'
25+
// CHECK-NEXT: ImplicitCastExpr 0x{{[0-9a-fA-F]+}} <col:52> 'uint':'unsigned int' <LValueToRValue>
26+
// CHECK-NEXT: MemberExpr 0x{{[0-9a-fA-F]+}} <col:52> 'uint':'unsigned int' lvalue ->handle
27+
// CHECK-NEXT: CXXThisExpr 0x{{[0-9a-fA-F]+}} <col:52> 'SimpleBuffer
28+
29+
// CHECK: CXXOperatorCallExpr 0x{{[0-9a-fA-F]+}} <col:29, col:58> 'const .Resource'
30+
// CHECK-NEXT: ImplicitCastExpr 0x{{[0-9a-fA-F]+}} <col:51, col:58> 'const .Resource (*)(unsigned int) const' <FunctionToPointerDecay>
31+
// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-fA-F]+}} <col:51, col:58> 'const .Resource (unsigned int) const' lvalue CXXMethod 0x{{[0-9a-fA-F]+}} 'operator[]' 'const .Resource (unsigned int) const'
32+
// CHECK-NEXT: ImplicitCastExpr 0x{{[0-9a-fA-F]+}} <col:29> 'const .Resource' lvalue <NoOp>
33+
// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-fA-F]+}} <col:29> '.Resource' lvalue Var 0x{{[0-9a-fA-F]+}} 'ResourceDescriptorHeap' '.Resource'
34+
// CHECK-NEXT: ImplicitCastExpr 0x{{[0-9a-fA-F]+}} <col:52> 'uint':'unsigned int' <LValueToRValue>
35+
// CHECK-NEXT: MemberExpr 0x{{[0-9a-fA-F]+}} <col:52> 'uint':'unsigned int' lvalue ->handle
36+
// CHECK-NEXT: CXXThisExpr 0x{{[0-9a-fA-F]+}} <col:52> 'SimpleBuffer

0 commit comments

Comments
 (0)