Skip to content

Commit

Permalink
Fix bool attribute argument handling (#6573)
Browse files Browse the repository at this point in the history
Bool attribute argument values of true would be interpreted as -1 and
generate a warning that it expects a uint literal argument.

This change translates bool expression to either 0 or 1 when translating
to int, just as normal expression evaluation would.
  • Loading branch information
tex3d authored May 3, 2024
1 parent 5ffab31 commit c7da630
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tools/clang/lib/Sema/SemaHLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12336,7 +12336,11 @@ static int ValidateAttributeIntArg(Sema &S, const AttributeList &Attr,
} else {
if (ArgNum.isInt()) {
value = ArgNum.getInt().getSExtValue();
if (!(E->getType()->isIntegralType(S.Context)) || value < 0) {
if (E->getType()->isBooleanType()) {
// Bool should map to 0 or 1. Otherwise, we would see -1 and emit a
// warning.
value = value ? 1 : 0;
} else if (!(E->getType()->isIntegralType(S.Context)) || value < 0) {
S.Diag(Attr.getLoc(), diag::warn_hlsl_attribute_expects_uint_literal)
<< Attr.getName();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,21 @@ void compute_node_topology() {}
[OutputTopology("triangle")]
[NodeMaxInputRecordsPerGraphEntryRecord(7, false)] // expected-error {{attribute nodemaxinputrecordspergraphentryrecord only allowed on node shaders}}
void compute_node_maxrecs() {}

// Check a few valid cases as well.

[Shader("node")]
[NodeLaunch("mesh")]
[OutputTopology("triangle")]
[NumThreads(42,1,1)]
[NodeDispatchGrid(19,84,1)]
[NodeMaxInputRecordsPerGraphEntryRecord(11, false)]
void valid_mesh_max_input_records() {}

[Shader("node")]
[NodeLaunch("mesh")]
[NumThreads(122,1,1)]
[NodeDispatchGrid(17,76,1)]
[OutputTopology("line")]
[NodeMaxInputRecordsPerGraphEntryRecord(13, true)]
void valid_mesh_max_input_records_shared() {}

0 comments on commit c7da630

Please sign in to comment.