Skip to content

Commit

Permalink
Move MaxRecords vs MaxRecordsSharedWith diagnostic
Browse files Browse the repository at this point in the history
A node output parameter may not have both the MaxRecords and
MaxRecordsShared with attribute. Moved the error diagnostic
for this case from CodeGen to Sema, and replaced the FileCheck
test with a verifier test case.
  • Loading branch information
Tim Corringham committed Jul 27, 2023
1 parent 680ab66 commit f3f7419
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 43 deletions.
2 changes: 2 additions & 0 deletions tools/clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -7818,6 +7818,8 @@ def err_hlsl_maxrecursiondepth_exceeded : Error<
"NodeMaxRecursionDepth may not exceed 32">;
def err_hlsl_too_many_node_inputs : Error<
"Node shader '%0' may not have more than one input record">;
def err_hlsl_incompatible_param_attr : Error<
"parameter '%0' may not have both '%1' and '%2'">;
// HLSL Change Ends

// SPIRV Change Starts
Expand Down
8 changes: 1 addition & 7 deletions tools/clang/lib/CodeGen/CGHLSLMS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2523,14 +2523,8 @@ void CGMSHLSLRuntime::AddHLSLFunctionInfo(Function *F, const FunctionDecl *FD) {
}
node.MaxRecordsSharedWith = ix;
}
if (const auto *Attr = parmDecl->getAttr<HLSLMaxRecordsAttr>()) {
if (node.MaxRecordsSharedWith >= 0) {
Diags.Report(parmDecl->getLocation(), Diags.getCustomDiagID(
DiagnosticsEngine::Error,
"Only one of MaxRecords or MaxRecordsSharedWith may be specified to the same parameter."));
}
if (const auto *Attr = parmDecl->getAttr<HLSLMaxRecordsAttr>())
node.MaxRecords = Attr->getMaxCount();
}
}

if (inputPatchCount > 1) {
Expand Down
6 changes: 6 additions & 0 deletions tools/clang/lib/Sema/SemaHLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11462,6 +11462,12 @@ class WorkGraphVisitor : public RecursiveASTVisitor<WorkGraphVisitor> {
<< funcName << P->getSourceRange();
}
}
// MaxRecords and MaxRecordsSharedWith are mutually exclusive
if (auto *maxShared = P->getAttr<HLSLMaxRecordsSharedWithAttr>())
if (auto *maxRecs = P->getAttr<HLSLMaxRecordsAttr>())
S.Diags.Report(P->getLocation(), diag::err_hlsl_incompatible_param_attr)
<< P->getName() << maxShared->getSpelling() << maxRecs->getSpelling()
<< P->getSourceRange();

return true;
}
Expand Down
6 changes: 6 additions & 0 deletions tools/clang/test/HLSL/workgraph/node_input_compatibility.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,9 @@ void node17(ThreadNodeInputRecord<RECORD> input,
NodeOutput<RECORD> output,
RWThreadNodeInputRecord<RECORD> input2) // expected-error {{Node shader 'node17' may not have more than one input record}}
{ }

[Shader("node")]
[NodeLaunch("thread")]
void node18(NodeOutput<RECORD> firstOut,
[MaxRecords(5)][MaxRecordsSharedWith(firstOut)] NodeOutput<RECORD> secondOut) // expected-error {{parameter 'secondOut' may not have both 'maxrecordssharedwith' and 'MaxRecords'}}
{ }

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
// Duplicate MaxRecords info with matching limits


// CHECK: 28:68: error: Only one of MaxRecords or MaxRecordsSharedWith may be specified to the same parameter.
// CHECK: 29:68: error: Only one of MaxRecords or MaxRecordsSharedWith may be specified to the same parameter.
// CHECK: 30:68: error: Only one of MaxRecords or MaxRecordsSharedWith may be specified to the same parameter.
// CHECK: 31:68: error: Only one of MaxRecords or MaxRecordsSharedWith may be specified to the same parameter.
// CHECK: 28:68: error: parameter 'Output2' may not have both 'maxrecordssharedwith' and 'MaxRecords'
// CHECK: 29:68: error: parameter 'Output3' may not have both 'maxrecordssharedwith' and 'MaxRecords'
// CHECK: 30:68: error: parameter 'Output4' may not have both 'maxrecordssharedwith' and 'MaxRecords'
// CHECK: 31:68: error: parameter 'Output5' may not have both 'maxrecordssharedwith' and 'MaxRecords'

struct rec0
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

// Duplicate MaxRecords info with mismatching limits

// CHECK: 27:68: error: Only one of MaxRecords or MaxRecordsSharedWith may be specified to the same parameter.
// CHECK: 28:68: error: Only one of MaxRecords or MaxRecordsSharedWith may be specified to the same parameter.
// CHECK: 29:68: error: Only one of MaxRecords or MaxRecordsSharedWith may be specified to the same parameter.
// CHECK: 30:68: error: Only one of MaxRecords or MaxRecordsSharedWith may be specified to the same parameter.
// CHECK: 27:68: error: parameter 'Output2' may not have both 'maxrecordssharedwith' and 'MaxRecords'
// CHECK: 28:68: error: parameter 'Output3' may not have both 'maxrecordssharedwith' and 'MaxRecords'
// CHECK: 29:68: error: parameter 'Output4' may not have both 'maxrecordssharedwith' and 'MaxRecords'
// CHECK: 30:68: error: parameter 'Output5' may not have both 'maxrecordssharedwith' and 'MaxRecords'

struct rec0
{
Expand Down

0 comments on commit f3f7419

Please sign in to comment.