Skip to content

Commit 82832bc

Browse files
committed
fix validation logic
1 parent 03cb514 commit 82832bc

File tree

6 files changed

+53
-6
lines changed

6 files changed

+53
-6
lines changed

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,8 +1322,8 @@ bool SemaHLSL::handleRootSignatureElements(
13221322
ReportError(Loc, 1, 0xfffffffe);
13231323
}
13241324

1325-
if (!llvm::hlsl::rootsig::verifyDescriptorRangeFlag(Version, Clause->Type,
1326-
Clause->Flags))
1325+
if (!llvm::hlsl::rootsig::verifyDescriptorRangeFlag(
1326+
Version, Clause->Type, llvm::to_underlying(Clause->Flags)))
13271327
ReportFlagError(Loc);
13281328
}
13291329
}

llvm/include/llvm/Frontend/HLSL/RootSignatureValidations.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ LLVM_ABI bool verifyRootDescriptorFlag(uint32_t Version, uint32_t FlagsVal);
3232
LLVM_ABI bool verifyRangeType(uint32_t Type);
3333
LLVM_ABI bool verifyDescriptorRangeFlag(uint32_t Version,
3434
dxil::ResourceClass Type,
35-
dxbc::DescriptorRangeFlags FlagsVal);
35+
uint32_t FlagsVal);
3636
LLVM_ABI bool verifyStaticSamplerFlags(uint32_t Version, uint32_t FlagsNumber);
3737
LLVM_ABI bool verifyNumDescriptors(uint32_t NumDescriptors);
3838
LLVM_ABI bool verifyMipLODBias(float MipLODBias);

llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,7 @@ Error MetadataParser::validateRootSignature(
665665
"NumDescriptors", Range.NumDescriptors));
666666

667667
if (!hlsl::rootsig::verifyDescriptorRangeFlag(
668-
RSD.Version, Range.RangeType,
669-
dxbc::DescriptorRangeFlags(Range.Flags)))
668+
RSD.Version, Range.RangeType, Range.Flags))
670669
DeferredErrs =
671670
joinErrors(std::move(DeferredErrs),
672671
make_error<RootSignatureValidationError<uint32_t>>(

llvm/lib/Frontend/HLSL/RootSignatureValidations.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ bool verifyRegisterSpace(uint32_t RegisterSpace) {
3636

3737
bool verifyRootDescriptorFlag(uint32_t Version, uint32_t FlagsVal) {
3838
using FlagT = dxbc::RootDescriptorFlags;
39+
uint32_t LargestValue =
40+
llvm::to_underlying(FlagT::LLVM_BITMASK_LARGEST_ENUMERATOR);
41+
if (FlagsVal >= NextPowerOf2(LargestValue))
42+
return false;
43+
3944
FlagT Flags = FlagT(FlagsVal);
4045
if (Version == 1)
4146
return Flags == FlagT::DataVolatile;
@@ -54,9 +59,14 @@ bool verifyRootDescriptorFlag(uint32_t Version, uint32_t FlagsVal) {
5459
}
5560

5661
bool verifyDescriptorRangeFlag(uint32_t Version, dxil::ResourceClass Type,
57-
dxbc::DescriptorRangeFlags Flags) {
62+
uint32_t FlagsVal) {
5863
using FlagT = dxbc::DescriptorRangeFlags;
64+
uint32_t LargestValue =
65+
llvm::to_underlying(FlagT::LLVM_BITMASK_LARGEST_ENUMERATOR);
66+
if (FlagsVal >= NextPowerOf2(LargestValue))
67+
return false;
5968

69+
FlagT Flags = FlagT(FlagsVal);
6070
const bool IsSampler = (Type == dxil::ResourceClass::Sampler);
6171

6272
if (Version == 1) {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; RUN: not opt -passes='print<dxil-root-signature>' %s -S -o - 2>&1 | FileCheck %s
2+
3+
target triple = "dxil-unknown-shadermodel6.0-compute"
4+
5+
; CHECK: error: Invalid value for DescriptorFlag: 66666
6+
; CHECK-NOT: Root Signature Definitions
7+
8+
define void @main() #0 {
9+
entry:
10+
ret void
11+
}
12+
attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
13+
14+
15+
!dx.rootsignatures = !{!2} ; list of function/root signature pairs
16+
!2 = !{ ptr @main, !3, i32 2 } ; function, root signature
17+
!3 = !{ !5 } ; list of root signature elements
18+
!5 = !{ !"DescriptorTable", i32 0, !6, !7 }
19+
!6 = !{ !"SRV", i32 1, i32 1, i32 0, i32 -1, i32 66666 }
20+
!7 = !{ !"UAV", i32 5, i32 1, i32 10, i32 5, i32 2 }
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; RUN: not opt -passes='print<dxil-root-signature>' %s -S -o - 2>&1 | FileCheck %s
2+
3+
target triple = "dxil-unknown-shadermodel6.0-compute"
4+
5+
6+
; CHECK: error: Invalid value for RootDescriptorFlag: 666
7+
; CHECK-NOT: Root Signature Definitions
8+
define void @main() #0 {
9+
entry:
10+
ret void
11+
}
12+
attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
13+
14+
15+
!dx.rootsignatures = !{!2} ; list of function/root signature pairs
16+
!2 = !{ ptr @main, !3, i32 2 } ; function, root signature
17+
!3 = !{ !5 } ; list of root signature elements
18+
!5 = !{ !"RootCBV", i32 0, i32 1, i32 2, i32 666 }

0 commit comments

Comments
 (0)