================
@@ -2361,6 +2361,99 @@ static bool DiagnoseHLSLRegisterAttribute(Sema &S, 
SourceLocation &ArgLoc,
   return ValidateMultipleRegisterAnnotations(S, D, RegType);
 }
 
+bool ExceedsUInt32Max(llvm::StringRef S) {
+  constexpr size_t MaxDigits = 10; // UINT32_MAX = 4294967295
+  if (S.size() > MaxDigits)
+    return true;
+
+  if (S.size() < MaxDigits)
+    return false;
+
+  return S.compare("4294967295") > 0;
+}
+
+// return false if the slot count exceeds the limit, true otherwise
+static bool AccumulateHLSLResourceSlots(QualType Ty, llvm::APInt &SlotCount,
+                                        const llvm::APInt &Limit,
+                                        ASTContext &Ctx,
+                                        uint64_t Multiplier = 1) {
+  Ty = Ty.getCanonicalType();
+  const Type *T = Ty.getTypePtr();
+
+  // Early exit if already overflowed
+  if (SlotCount.ugt(Limit))
+    return false;
+
+  // Case 1: array type
+  if (const auto *AT = dyn_cast<ArrayType>(T)) {
+    uint64_t Count = 1;
+
+    if (const auto *CAT = dyn_cast<ConstantArrayType>(AT)) {
+      Count = CAT->getSize().getZExtValue();
+    }
+    // TODO: how do we handle non constant resource arrays?
----------------
damyanp wrote:

Ah, ok, those are unbounded resource arrays. Really the compiler can only 
validate that against the root signature - and while it could it seems that 
neither clang nor DXC does: https://godbolt.org/z/r54neEsqz

IMO we should remove the TODO and file an issue with some repros.

https://github.com/llvm/llvm-project/pull/174028
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to