Skip to content

Commit 44008e2

Browse files
committed
gross C++
1 parent 0a96251 commit 44008e2

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

llvm/lib/Transforms/Scalar/SROA.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ static void migrateDebugInfo(AllocaInst *OldAlloca, bool IsSplit,
379379
DIBuilder DIB(*OldInst->getModule(), /*AllowUnresolved*/ false);
380380
assert(OldAlloca->isStaticAlloca());
381381

382-
auto MigrateDbgAssign = [&](auto *DbgAssign) {
382+
auto MigrateDbgAssign = [&](auto *DbgAssign, auto *DbgInstType) {
383383
LLVM_DEBUG(dbgs() << " existing dbg.assign is: " << *DbgAssign
384384
<< "\n");
385385
auto *Expr = DbgAssign->getExpression();
@@ -436,12 +436,16 @@ static void migrateDebugInfo(AllocaInst *OldAlloca, bool IsSplit,
436436
// insertDbgAssign returns a PointerUnion of {Instruction* | DbgRecord*}.
437437
// If DbgAssign is a DPValue* it'll return a DbgRecord*, otherwise if
438438
// 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)>(
440444
DIB.insertDbgAssign(Inst, NewValue, DbgAssign->getVariable(), Expr,
441445
Dest,
442446
DIExpression::get(Expr->getContext(), std::nullopt),
443447
DbgAssign->getDebugLoc())
444-
.getOpaqueValue());
448+
.template get<decltype(DbgInstType)>());
445449

446450
// If we've updated the value but the original dbg.assign has an arglist
447451
// then kill it now - we can't use the requested new value.
@@ -478,8 +482,12 @@ static void migrateDebugInfo(AllocaInst *OldAlloca, bool IsSplit,
478482
LLVM_DEBUG(dbgs() << "Created new assign: " << *NewAssign << "\n");
479483
};
480484

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+
});
483491
}
484492

485493
namespace {

0 commit comments

Comments
 (0)