[clang] Implement `ByteAddressBuffer` Load/Store methods (PR #176058)
Justin Bogner via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 21 10:26:49 PST 2026
================
@@ -3306,11 +3306,31 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
SemaRef.getASTContext().UnsignedIntTy))
return true;
+ // Figure out the return type of the intrinsic. For most resources it is the
+ // contained type. For ByteAddressBuffer it is determined by the type used
+ // on the FunctionDecl.
auto *ResourceTy =
TheCall->getArg(0)->getType()->castAs<HLSLAttributedResourceType>();
- QualType ContainedTy = ResourceTy->getContainedType();
+ QualType ElementTy = ResourceTy->getContainedType();
+ if (ResourceTy->getAttrs().RawBuffer && ElementTy->isChar8Type()) {
+ // Load method uses return type
+ FunctionDecl *FD = dyn_cast<FunctionDecl>(SemaRef.CurContext);
+ ElementTy = FD->getReturnType();
+ // Store method uses 2nd parameter type
+ if (ElementTy->isVoidType()) {
+ assert(FD->getNumParams() == 2 &&
+ "expected 2 parameters for Store method");
+ ElementTy = FD->getParamDecl(1)->getType();
+ }
----------------
bogner wrote:
> We could have a separate `resource_getpointer`-like builtin function with an extra argument of the dependent type, and the return type for the intrinsic could be inferred from that.
This is a little ugly, but it should be better behaved and safer than the current approach. @kmpeng can you try this?
https://github.com/llvm/llvm-project/pull/176058
More information about the cfe-commits
mailing list