Skip to content

Commit c7da630

Browse files
authored
Fix bool attribute argument handling (#6573)
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.
1 parent 5ffab31 commit c7da630

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

tools/clang/lib/Sema/SemaHLSL.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12336,7 +12336,11 @@ static int ValidateAttributeIntArg(Sema &S, const AttributeList &Attr,
1233612336
} else {
1233712337
if (ArgNum.isInt()) {
1233812338
value = ArgNum.getInt().getSExtValue();
12339-
if (!(E->getType()->isIntegralType(S.Context)) || value < 0) {
12339+
if (E->getType()->isBooleanType()) {
12340+
// Bool should map to 0 or 1. Otherwise, we would see -1 and emit a
12341+
// warning.
12342+
value = value ? 1 : 0;
12343+
} else if (!(E->getType()->isIntegralType(S.Context)) || value < 0) {
1234012344
S.Diag(Attr.getLoc(), diag::warn_hlsl_attribute_expects_uint_literal)
1234112345
<< Attr.getName();
1234212346
}

tools/clang/test/CodeGenDXIL/hlsl/objects/NodeObjects/mesh-node-invalid-attribs.hlsl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,21 @@ void compute_node_topology() {}
7878
[OutputTopology("triangle")]
7979
[NodeMaxInputRecordsPerGraphEntryRecord(7, false)] // expected-error {{attribute nodemaxinputrecordspergraphentryrecord only allowed on node shaders}}
8080
void compute_node_maxrecs() {}
81+
82+
// Check a few valid cases as well.
83+
84+
[Shader("node")]
85+
[NodeLaunch("mesh")]
86+
[OutputTopology("triangle")]
87+
[NumThreads(42,1,1)]
88+
[NodeDispatchGrid(19,84,1)]
89+
[NodeMaxInputRecordsPerGraphEntryRecord(11, false)]
90+
void valid_mesh_max_input_records() {}
91+
92+
[Shader("node")]
93+
[NodeLaunch("mesh")]
94+
[NumThreads(122,1,1)]
95+
[NodeDispatchGrid(17,76,1)]
96+
[OutputTopology("line")]
97+
[NodeMaxInputRecordsPerGraphEntryRecord(13, true)]
98+
void valid_mesh_max_input_records_shared() {}

0 commit comments

Comments
 (0)