[llvm-branch-commits] [llvm] [DirectX] Improve error message when a binding cannot be found for a resource (PR #140642)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon May 19 16:01:40 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-directx

Author: Helena Kotas (hekota)

<details>
<summary>Changes</summary>

Closes #<!-- -->137868

Depends on #<!-- -->140633 

---
Full diff: https://github.com/llvm/llvm-project/pull/140642.diff


2 Files Affected:

- (modified) llvm/lib/Target/DirectX/DXILResourceImplicitBinding.cpp (+4-5) 
- (added) llvm/test/CodeGen/DirectX/ImplicitBinding/error.ll (+26) 


``````````diff
diff --git a/llvm/lib/Target/DirectX/DXILResourceImplicitBinding.cpp b/llvm/lib/Target/DirectX/DXILResourceImplicitBinding.cpp
index 72d410b55c7e5..3f1d055ba4418 100644
--- a/llvm/lib/Target/DirectX/DXILResourceImplicitBinding.cpp
+++ b/llvm/lib/Target/DirectX/DXILResourceImplicitBinding.cpp
@@ -32,11 +32,10 @@ namespace {
 static void diagnoseImplicitBindingNotFound(CallInst *ImplBindingCall) {
   Function *F = ImplBindingCall->getFunction();
   LLVMContext &Context = F->getParent()->getContext();
-  // FIXME: include the name of the resource in the error message
-  // (llvm/llvm-project#137868)
-  Context.diagnose(
-      DiagnosticInfoGenericWithLoc("resource cannot be allocated", *F,
-                                   ImplBindingCall->getDebugLoc(), DS_Error));
+  StringRef Name = getResourceNameFromBindingCall(ImplBindingCall);
+  Context.diagnose(DiagnosticInfoGenericWithLoc(
+      Twine("resource ") + Name + " cannot be allocated", *F,
+      ImplBindingCall->getDebugLoc(), DS_Error));
 }
 
 static bool assignBindings(Module &M, DXILResourceBindingInfo &DRBI,
diff --git a/llvm/test/CodeGen/DirectX/ImplicitBinding/error.ll b/llvm/test/CodeGen/DirectX/ImplicitBinding/error.ll
new file mode 100644
index 0000000000000..764b5b96ce38a
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/ImplicitBinding/error.ll
@@ -0,0 +1,26 @@
+; RUN: not opt -S -dxil-resource-implicit-binding %s 2>&1 | FileCheck %s
+
+target triple = "dxil-pc-shadermodel6.6-compute"
+
+ at A.str = private unnamed_addr constant [2 x i8] c"A\00", align 1
+ at B.str = private unnamed_addr constant [2 x i8] c"B\00", align 1
+ at C.str = private unnamed_addr constant [2 x i8] c"C\00", align 1
+
+define void @test_simple_binding() {
+
+; StructuredBuffer<float> A[] : register(t1);
+  %bufA = call target("dx.RawBuffer", float, 0, 0)
+      @llvm.dx.resource.handlefrombinding(i32 0, i32 1, i32 -1, i32 0, i1 false, ptr @A.str)
+
+; StructuredBuffer<float> B[2]; // does not fit in space0
+  %bufB = call target("dx.RawBuffer", float, 0, 0)
+      @llvm.dx.resource.handlefromimplicitbinding(i32 100, i32 0, i32 2, i32 0, i1 false, ptr @B.str)
+
+; StructuredBuffer<float> C; // ok
+  %bufC = call target("dx.RawBuffer", float, 0, 0)
+      @llvm.dx.resource.handlefromimplicitbinding(i32 200, i32 0, i32 1, i32 0, i1 false, ptr @C.str)
+
+; CHECK: error:{{.*}} resource B cannot be allocated
+
+  ret void
+}

``````````

</details>


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


More information about the llvm-branch-commits mailing list