diff options
author | joaosaffran <joaosaffranllvm@gmail.com> | 2025-10-06 14:21:28 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-10-06 17:21:28 -0400 |
commit | 58ce3e20e55c67298da94eabe4e25f8baeb45fa7 (patch) | |
tree | c53883f31e83293c4e13556e8a1b3779f3f9ca52 /llvm/lib/Frontend/HLSL/RootSignatureValidations.cpp | |
parent | 74af5784a570914271a258618bf6f7cb06c50241 (diff) | |
download | llvm-58ce3e20e55c67298da94eabe4e25f8baeb45fa7.zip llvm-58ce3e20e55c67298da94eabe4e25f8baeb45fa7.tar.gz llvm-58ce3e20e55c67298da94eabe4e25f8baeb45fa7.tar.bz2 |
[DirectX] Fix Flags validation to prevent casting into enum (#161587)
This PR changes the validation logic for Root Descriptor and Descriptor
Range flags to properly check if the `uint32_t` values are within range
before casting into the enums.
Diffstat (limited to 'llvm/lib/Frontend/HLSL/RootSignatureValidations.cpp')
-rw-r--r-- | llvm/lib/Frontend/HLSL/RootSignatureValidations.cpp | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/llvm/lib/Frontend/HLSL/RootSignatureValidations.cpp b/llvm/lib/Frontend/HLSL/RootSignatureValidations.cpp index 8a2b03d..30408df 100644 --- a/llvm/lib/Frontend/HLSL/RootSignatureValidations.cpp +++ b/llvm/lib/Frontend/HLSL/RootSignatureValidations.cpp @@ -34,7 +34,8 @@ bool verifyRegisterSpace(uint32_t RegisterSpace) { return !(RegisterSpace >= 0xFFFFFFF0); } -bool verifyRootDescriptorFlag(uint32_t Version, uint32_t FlagsVal) { +bool verifyRootDescriptorFlag(uint32_t Version, + dxbc::RootDescriptorFlags FlagsVal) { using FlagT = dxbc::RootDescriptorFlags; FlagT Flags = FlagT(FlagsVal); if (Version == 1) @@ -56,7 +57,6 @@ bool verifyRootDescriptorFlag(uint32_t Version, uint32_t FlagsVal) { bool verifyDescriptorRangeFlag(uint32_t Version, dxil::ResourceClass Type, dxbc::DescriptorRangeFlags Flags) { using FlagT = dxbc::DescriptorRangeFlags; - const bool IsSampler = (Type == dxil::ResourceClass::Sampler); if (Version == 1) { @@ -113,13 +113,8 @@ bool verifyDescriptorRangeFlag(uint32_t Version, dxil::ResourceClass Type, return (Flags & ~Mask) == FlagT::None; } -bool verifyStaticSamplerFlags(uint32_t Version, uint32_t FlagsNumber) { - uint32_t LargestValue = llvm::to_underlying( - dxbc::StaticSamplerFlags::LLVM_BITMASK_LARGEST_ENUMERATOR); - if (FlagsNumber >= NextPowerOf2(LargestValue)) - return false; - - dxbc::StaticSamplerFlags Flags = dxbc::StaticSamplerFlags(FlagsNumber); +bool verifyStaticSamplerFlags(uint32_t Version, + dxbc::StaticSamplerFlags Flags) { if (Version <= 2) return Flags == dxbc::StaticSamplerFlags::None; |