https://github.com/hekota created https://github.com/llvm/llvm-project/pull/140642
Closes #137868 Depends on #140633 >From 9ba94a335ffca203b7299f363ea8663a46d64bf8 Mon Sep 17 00:00:00 2001 From: Helena Kotas <heko...@microsoft.com> Date: Mon, 19 May 2025 15:57:02 -0700 Subject: [PATCH] [DirectX] Improve error message when a binding cannot be found for a resource --- .../DirectX/DXILResourceImplicitBinding.cpp | 9 +++---- .../CodeGen/DirectX/ImplicitBinding/error.ll | 26 +++++++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 llvm/test/CodeGen/DirectX/ImplicitBinding/error.ll 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 +} _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits