Skip to content

Commit 86775ab

Browse files
committed
correct validation
1 parent 4be1099 commit 86775ab

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,7 @@ bool SemaHLSL::handleRootSignatureElements(
13611361
bool HasAnySampler = false;
13621362
bool HasAnyNonSampler = false;
13631363
uint32_t Offset = 0;
1364+
bool Unbound = false;
13641365
for (const auto &[Clause, ClauseElem] : UnboundClauses) {
13651366
SourceLocation Loc = ClauseElem->getLocation();
13661367
if (Clause->Type == llvm::dxil::ResourceClass::Sampler)
@@ -1381,22 +1382,25 @@ bool SemaHLSL::handleRootSignatureElements(
13811382
llvm::hlsl::rootsig::DescriptorTableOffsetAppend) {
13821383
// Manually specified the offset
13831384
Offset = Clause->Offset;
1385+
Unbound = false;
1386+
} else if (Unbound) {
1387+
// Trying to append onto unbound offset
1388+
Diag(Loc, diag::err_hlsl_appending_onto_unbound);
13841389
}
13851390

13861391
uint64_t RangeBound = llvm::hlsl::rootsig::computeRangeBound(
13871392
Offset, Clause->NumDescriptors);
13881393

1389-
if (!llvm::hlsl::rootsig::verifyBoundOffset(Offset)) {
1390-
// Trying to append onto unbound offset
1391-
Diag(Loc, diag::err_hlsl_appending_onto_unbound);
1392-
} else if (!llvm::hlsl::rootsig::verifyNoOverflowedOffset(RangeBound)) {
1394+
if (!llvm::hlsl::rootsig::verifyNoOverflowedOffset(RangeBound)) {
13931395
// Upper bound overflows maximum offset
13941396
Diag(Loc, diag::err_hlsl_offset_overflow) << Offset << RangeBound;
13951397
}
13961398

13971399
Offset = RangeBound == llvm::hlsl::rootsig::NumDescriptorsUnbounded
13981400
? uint32_t(RangeBound)
13991401
: uint32_t(RangeBound + 1);
1402+
Unbound = Clause->NumDescriptors ==
1403+
llvm::hlsl::rootsig::NumDescriptorsUnbounded;
14001404

14011405
// Compute the register bounds and track resource binding
14021406
uint32_t LowerBound(Clause->Reg.Number);

clang/test/SemaHLSL/RootSignature-resource-ranges-err.hlsl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,8 @@ void append_offset_overflow_signature() {}
141141

142142
// expected-error@+1 {{descriptor range offset overflows [4294967292, 4294967296]}}
143143
[RootSignature("DescriptorTable(CBV(b0, offset = 4294967292, numDescriptors = 5))")]
144-
void offset_() {}
144+
void offset_overflow() {}
145+
146+
// expected-error@+1 {{descriptor range offset overflows [4294967295, 4294967296]}}
147+
[RootSignature("DescriptorTable(CBV(b0, offset = 4294967294), CBV(b1, numDescriptors = 2))")]
148+
void appended_offset_overflow() {}

clang/test/SemaHLSL/RootSignature-resource-ranges.hlsl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ void valid_root_signature_6() {}
2525

2626
[RootSignature("DescriptorTable(CBV(b0, offset = 4294967292), CBV(b1, numDescriptors = 3))")]
2727
void valid_root_signature_7() {}
28+
29+
[RootSignature("DescriptorTable(CBV(b0, offset = 4294967294), CBV(b1))")]
30+
void valid_root_signature_8() {}

0 commit comments

Comments
 (0)