[clang] [llvm] [HLSL] Add load overload with status (PR #166449)

Helena Kotas via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 19 11:13:14 PST 2025


================
@@ -1232,6 +1233,30 @@ BuiltinTypeDeclBuilder &BuiltinTypeDeclBuilder::addDecrementCounterMethod() {
       .finalize();
 }
 
+BuiltinTypeDeclBuilder &
+BuiltinTypeDeclBuilder::addLoadWithStatusFunction(DeclarationName &Name,
+                                                  bool IsConst) {
+  assert(!Record->isCompleteDefinition() && "record is already complete");
+  ASTContext &AST = SemaRef.getASTContext();
+  using PH = BuiltinTypeMethodBuilder::PlaceHolder;
+
+  QualType ReturnTy = getHandleElementType();
+  BuiltinTypeMethodBuilder::LocalVar ResultVar("Result", ReturnTy);
+  BuiltinTypeMethodBuilder::LocalVar StatusVar("StatusBool", AST.BoolTy);
+
+  return BuiltinTypeMethodBuilder(*this, Name, ReturnTy, IsConst)
+      .addParam("Index", AST.UnsignedIntTy)
+      .addParam("Status", AST.UnsignedIntTy, HLSLParamModifierAttr::Keyword_out)
+      .declareLocalVar(ResultVar)
+      .declareLocalVar(StatusVar)
+      .callBuiltin("__builtin_hlsl_resource_load_with_status", ReturnTy,
+                   PH::Handle, PH::_0, StatusVar)
+      .assign(ResultVar, PH::LastStmt)
+      .assign(PH::_1, StatusVar)
+      .returnValue(ResultVar)
----------------
hekota wrote:

I believe this should work:

```suggestion
      .callBuiltin("__builtin_hlsl_resource_load_with_status", ReturnTy,
                   PH::Handle, PH::_0, PH::_1)
```

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


More information about the llvm-commits mailing list