[clang] [HLSL][Sema] Validate that occupied register numbers never exceed UINT32_MAX (PR #174028)
Finn Plummer via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 31 12:53:53 PST 2025
================
@@ -2419,12 +2498,24 @@ void SemaHLSL::handleResourceBindingAttr(Decl *TheDecl, const ParsedAttr &AL) {
Diag(SlotLoc, diag::warn_hlsl_deprecated_register_type_i);
return;
}
- StringRef SlotNumStr = Slot.substr(1);
+ const StringRef SlotNumStr = Slot.substr(1);
+
unsigned N;
- if (SlotNumStr.getAsInteger(10, N)) {
+
+ // validate that the slot number is a non-empty number
+ if (SlotNumStr.empty() || !llvm::all_of(SlotNumStr, llvm::isDigit)) {
Diag(SlotLoc, diag::err_hlsl_unsupported_register_number);
return;
}
+
+ // Validate register number. It should not exceed UINT32_MAX,
+ // including if the resource type is an array that starts
+ // before UINT32_MAX, but ends afterwards.
+ if (ValidateRegisterNumber(SlotNumStr, TheDecl, getASTContext(), N)) {
----------------
inbelic wrote:
Take it or leave it nit:
```suggestion
uint64_t N;
if (SlotNumStr.getAsInteger(10, N) || ValidateRegisterNumber(N, TheDecl, getASTContext())) {
...
}
SlotNum = (uint32_t)N;
```
https://github.com/llvm/llvm-project/pull/174028
More information about the cfe-commits
mailing list