@@ -1036,12 +1036,26 @@ bool PrivateMemoryResolution::resolveAllocaInstructions(bool privateOnStack, boo
10361036 unsigned scalarBufferOffset = m_ModAllocaInfo->getBufferOffset (pAI);
10371037 unsigned bufferSize = m_ModAllocaInfo->getBufferStride (pAI);
10381038
1039- // Attach metadata to instruction containing offset of storage
1039+ // Attach metadata to instruction containing offset of storage.
1040+ // In LLVM >= 22 debug declares are DbgVariableRecord objects (not Instructions)
1041+ // and have no metadata slots. The DwarfDebug/DwarfCompileUnit consumers
1042+ // (buildFpBasedLoc, buildPrivateBaseRegBased) are also not yet migrated to
1043+ // the new debug-records API and cannot find these declares anyway, so skip
1044+ // the metadata for now.
1045+ // FIXME: once DwarfDebug is migrated to DbgVariableRecord, carry StorageOffset
1046+ // and StorageSize via an alternative mechanism (e.g. DbgVariableRecord side
1047+ // map or DIExpression extension).
1048+ #if LLVM_VERSION_MAJOR < 22
10401049 auto OffsetMD =
10411050 MDNode::get (builder.getContext (), ConstantAsMetadata::get (builder.getInt32 (scalarBufferOffset)));
10421051 DbgDcl->setMetadata (" StorageOffset" , OffsetMD);
10431052 auto SizeMD = MDNode::get (builder.getContext (), ConstantAsMetadata::get (builder.getInt32 (bufferSize)));
10441053 DbgDcl->setMetadata (" StorageSize" , SizeMD);
1054+ #else
1055+ (void )scalarBufferOffset;
1056+ (void )bufferSize;
1057+ (void )DbgDcl;
1058+ #endif
10451059 }
10461060 }
10471061 // Replace all uses of original alloca with the bitcast
@@ -1335,11 +1349,16 @@ bool PrivateMemoryResolution::resolveAllocaInstructions(bool privateOnStack, boo
13351349 if (modMD->compOpt .OptDisable ) {
13361350 auto DbgDcls = IGCLLVM::findDbgDeclareUses (pAI);
13371351 for (auto DbgDcl : DbgDcls) {
1338- // Attach metadata to instruction containing offset of storage
1352+ // Attach metadata to instruction containing offset of storage.
1353+ // FIXME: for llvm 22 (see above for more context).
1354+ #if LLVM_VERSION_MAJOR < 22
13391355 unsigned int scalarBufferOffset = m_ModAllocaInfo->getBufferOffset (pAI);
13401356 auto OffsetMD =
13411357 MDNode::get (builder.getContext (), ConstantAsMetadata::get (builder.getInt32 (scalarBufferOffset)));
13421358 DbgDcl->setMetadata (" StorageOffset" , OffsetMD);
1359+ #else
1360+ (void )DbgDcl;
1361+ #endif
13431362 }
13441363 }
13451364
0 commit comments