[llvm] [Analysis][DXILResource] Correct bound computation (PR #184198)

Tex Riddell via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 2 10:50:39 PST 2026


================
@@ -1067,15 +1067,17 @@ void DXILResourceBindingInfo::populate(Module &M, DXILResourceTypeMap &DRTM) {
               cast<ConstantInt>(CI->getArgOperand(0))->getZExtValue();
           uint32_t LowerBound =
               cast<ConstantInt>(CI->getArgOperand(1))->getZExtValue();
-          int32_t Size =
+          uint32_t Size =
               cast<ConstantInt>(CI->getArgOperand(2))->getZExtValue();
           Value *Name = CI->getArgOperand(4);
 
-          // negative size means unbounded resource array;
+          // UINT32_MAX (-1) size means unbounded resource array;
           // upper bound register overflow should be detected in Sema
-          assert((Size < 0 || (unsigned)LowerBound + Size - 1 <= UINT32_MAX) &&
+          assert((Size == UINT32_MAX ||
+                  (unsigned)LowerBound + Size - 1 <= UINT32_MAX) &&
----------------
tex3d wrote:

I think the expression `(unsigned)LowerBound + Size - 1 <= UINT32_MAX` can never be false, just as *all* uint32 values are `<= UINT32_MAX` by definition. This needs to be evaluated using `uint64_t` instead, or rely on `uint32_t` wrapping behavior and assert `LowerBound < LowerBound + Size - 1)`. Plus `(unsigned)` seems unnecessary now.

Another point, should this be an assert? Are we expecting this to always be caught earlier?

https://github.com/llvm/llvm-project/pull/184198


More information about the llvm-commits mailing list