File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed
test/CodeGen/DirectX/CBufferAccess Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -43,8 +43,13 @@ std::optional<CBufferMetadata> CBufferMetadata::get(Module &M) {
4343 for (const MDNode *MD : CBufMD->operands ()) {
4444 assert (MD->getNumOperands () && " Invalid cbuffer metadata" );
4545
46- auto *Handle = cast<GlobalVariable>(
47- cast<ValueAsMetadata>(MD->getOperand (0 ))->getValue ());
46+ // For an unused cbuffer, the handle may have been optimizzd out
47+ Metadata *OpMD = MD->getOperand (0 );
48+ if (!OpMD)
49+ continue ;
50+
51+ auto *Handle =
52+ cast<GlobalVariable>(cast<ValueAsMetadata>(OpMD)->getValue ());
4853 CBufferMapping &Mapping = Result->Mappings .emplace_back (Handle);
4954
5055 for (int I = 1 , E = MD->getNumOperands (); I < E; ++I) {
Original file line number Diff line number Diff line change 1+ ; RUN: opt -S -dxil-cbuffer-access -mtriple=dxil--shadermodel6.3-library %s | FileCheck %s
2+ ; Check that we correctly ignore cbuffers that were nulled out by optimizations.
3+
4+ %__cblayout_CB = type <{ float }>
5+ @CB.cb = local_unnamed_addr global target ("dx.CBuffer" , %__cblayout_CB ) poison
6+ @x = external local_unnamed_addr addrspace (2 ) global float , align 4
7+
8+ ; CHECK-NOT: !hlsl.cbs =
9+ !hlsl.cbs = !{!0 , !1 , !2 }
10+
11+ !0 = !{ptr @CB.cb , ptr addrspace (2 ) @x }
12+ !1 = !{ptr @CB.cb , null }
13+ !2 = !{null , null }
You can’t perform that action at this time.
0 commit comments