Skip to content

[DirectX] Improve error message when a binding cannot be found for a resource #140642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: users/hekota/pr140633-resource-names-to-analysis
Choose a base branch
from

Conversation

hekota
Copy link
Member

@hekota hekota commented May 19, 2025

Closes #137868

Depends on #140633

@llvmbot
Copy link
Member

llvmbot commented May 19, 2025

@llvm/pr-subscribers-backend-directx

Author: Helena Kotas (hekota)

Changes

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 --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"
+
+@A.str = private unnamed_addr constant [2 x i8] c"A\00", align 1
+@B.str = private unnamed_addr constant [2 x i8] c"B\00", align 1
+@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
+}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants