[clang] [llvm] [HLSL] Add `Increment`/`DecrementCounter` methods to structured buffers (PR #114148)
Tex Riddell via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 7 17:49:47 PST 2024
================
@@ -2161,6 +2186,22 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
return true;
break;
}
+ case Builtin::BI__builtin_hlsl_buffer_update_counter: {
+ if (SemaRef.checkArgCount(TheCall, 2) ||
+ CheckResourceHandle(&SemaRef, TheCall, 0) ||
+ CheckInt(&SemaRef, TheCall, 1))
+ return true;
+ Expr *OffsetExpr = TheCall->getArg(1);
+ std::optional<llvm::APSInt> Offset =
+ OffsetExpr->getIntegerConstantExpr(SemaRef.getASTContext());
+ if (!Offset.has_value() || abs(Offset->getExtValue()) != 1) {
+ SemaRef.Diag(TheCall->getArg(1)->getBeginLoc(),
----------------
tex3d wrote:
Shouldn't this be a specific int type (not an integer type of any size/signedness)? If so, couldn't we have a check function that takes a single type and call it like `CheckArgType(&SemaRef, TheCall, 1, SemaRef.Context.IntTy)`?
Or perhaps it could just be checked and diagnosed here instead?
```suggestion
if (SemaRef.checkArgCount(TheCall, 2) ||
CheckResourceHandle(&SemaRef, TheCall, 0))
return true;
Expr *OffsetExpr = TheCall->getArg(1);
SourceLocation OffsetLoc = OffsetExpr->getExprLoc();
if (OffsetExpr->getType() != SemaRef.Context.IntTy) {
S->Diag(OffsetLoc, diag::err_typecheck_expect_int) << ArgType;
return true;
}
std::optional<llvm::APSInt> Offset =
OffsetExpr->getIntegerConstantExpr(SemaRef.getASTContext());
if (!Offset.has_value() || abs(Offset->getExtValue()) != 1) {
SemaRef.Diag(OffsetLoc,
```
https://github.com/llvm/llvm-project/pull/114148
More information about the cfe-commits
mailing list