Skip to content

Commit eb0e78b

Browse files
authored
[DirectX] Improve error message when a binding cannot be found for a resource (#140642)
Closes #137868
1 parent a73cdb9 commit eb0e78b

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

llvm/lib/Target/DirectX/DXILResourceImplicitBinding.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,10 @@ namespace {
3232
static void diagnoseImplicitBindingNotFound(CallInst *ImplBindingCall) {
3333
Function *F = ImplBindingCall->getFunction();
3434
LLVMContext &Context = F->getParent()->getContext();
35-
// FIXME: include the name of the resource in the error message
36-
// (llvm/llvm-project#137868)
37-
Context.diagnose(
38-
DiagnosticInfoGenericWithLoc("resource cannot be allocated", *F,
39-
ImplBindingCall->getDebugLoc(), DS_Error));
35+
StringRef Name = getResourceNameFromBindingCall(ImplBindingCall);
36+
Context.diagnose(DiagnosticInfoGenericWithLoc(
37+
Twine("resource ") + Name + " cannot be allocated", *F,
38+
ImplBindingCall->getDebugLoc(), DS_Error));
4039
}
4140

4241
static bool assignBindings(Module &M, DXILResourceBindingInfo &DRBI,
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
; RUN: not opt -S -dxil-resource-implicit-binding %s 2>&1 | FileCheck %s
2+
3+
target triple = "dxil-pc-shadermodel6.6-compute"
4+
5+
@A.str = private unnamed_addr constant [2 x i8] c"A\00", align 1
6+
@B.str = private unnamed_addr constant [2 x i8] c"B\00", align 1
7+
@C.str = private unnamed_addr constant [2 x i8] c"C\00", align 1
8+
9+
define void @test_simple_binding() {
10+
11+
; StructuredBuffer<float> A[] : register(t1);
12+
%bufA = call target("dx.RawBuffer", float, 0, 0)
13+
@llvm.dx.resource.handlefrombinding(i32 0, i32 1, i32 -1, i32 0, i1 false, ptr @A.str)
14+
15+
; StructuredBuffer<float> B[2]; // does not fit in space0
16+
%bufB = call target("dx.RawBuffer", float, 0, 0)
17+
@llvm.dx.resource.handlefromimplicitbinding(i32 100, i32 0, i32 2, i32 0, i1 false, ptr @B.str)
18+
19+
; StructuredBuffer<float> C; // ok
20+
%bufC = call target("dx.RawBuffer", float, 0, 0)
21+
@llvm.dx.resource.handlefromimplicitbinding(i32 200, i32 0, i32 1, i32 0, i1 false, ptr @C.str)
22+
23+
; CHECK: error:{{.*}} resource B cannot be allocated
24+
25+
ret void
26+
}

0 commit comments

Comments
 (0)