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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions llvm/lib/Target/DirectX/DXILResourceImplicitBinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
26 changes: 26 additions & 0 deletions llvm/test/CodeGen/DirectX/ImplicitBinding/error.ll
Original file line number Diff line number Diff line change
@@ -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
}