@@ -379,7 +379,7 @@ static void migrateDebugInfo(AllocaInst *OldAlloca, bool IsSplit,
379
379
DIBuilder DIB (*OldInst->getModule (), /* AllowUnresolved*/ false );
380
380
assert (OldAlloca->isStaticAlloca ());
381
381
382
- auto MigrateDbgAssign = [&](auto *DbgAssign) {
382
+ auto MigrateDbgAssign = [&](auto *DbgAssign, auto *DbgInstType ) {
383
383
LLVM_DEBUG (dbgs () << " existing dbg.assign is: " << *DbgAssign
384
384
<< " \n " );
385
385
auto *Expr = DbgAssign->getExpression ();
@@ -436,12 +436,16 @@ static void migrateDebugInfo(AllocaInst *OldAlloca, bool IsSplit,
436
436
// insertDbgAssign returns a PointerUnion of {Instruction* | DbgRecord*}.
437
437
// If DbgAssign is a DPValue* it'll return a DbgRecord*, otherwise if
438
438
// DbgAssign is a DbgAssignIntrinsic* it'll return a Instruction*.
439
- decltype (DbgAssign) NewAssign = reinterpret_cast <decltype (DbgAssign)>(
439
+ // The ugly code below creates a new debug marker, then gets the
440
+ // pointer type out of the union based on the type of DbgInstType
441
+ // (Instruction* or DbgRecord*), which is then cast to DbgAssignIntrinsic*
442
+ // or DPValue* so that the relevant member functions can be called.
443
+ auto *NewAssign = static_cast <decltype (DbgAssign)>(
440
444
DIB.insertDbgAssign (Inst, NewValue, DbgAssign->getVariable (), Expr,
441
445
Dest,
442
446
DIExpression::get (Expr->getContext (), std::nullopt),
443
447
DbgAssign->getDebugLoc ())
444
- .getOpaqueValue ());
448
+ .template get < decltype (DbgInstType)> ());
445
449
446
450
// If we've updated the value but the original dbg.assign has an arglist
447
451
// then kill it now - we can't use the requested new value.
@@ -478,8 +482,12 @@ static void migrateDebugInfo(AllocaInst *OldAlloca, bool IsSplit,
478
482
LLVM_DEBUG (dbgs () << " Created new assign: " << *NewAssign << " \n " );
479
483
};
480
484
481
- for_each (MarkerRange, MigrateDbgAssign);
482
- for_each (DPVAssignMarkerRange, MigrateDbgAssign);
485
+ for_each (MarkerRange, [&](DbgAssignIntrinsic *DAI) {
486
+ MigrateDbgAssign (DAI, static_cast <Instruction *>(nullptr ));
487
+ });
488
+ for_each (DPVAssignMarkerRange, [&](DPValue *DPV) {
489
+ MigrateDbgAssign (DPV, static_cast <DbgRecord *>(nullptr ));
490
+ });
483
491
}
484
492
485
493
namespace {
0 commit comments