Skip to content

Commit

Permalink
[DebugInfo][RemoveDIs] Set new-dbg-info flag from Modules correctly (#…
Browse files Browse the repository at this point in the history
…82373)

It turns out there's a pathway for Functions to be inserted into modules
without having the "New" debug-info flag set correctly, which this patch
fixes. Sadly there isn't a Module::insert method to instrument out
there, everyone touches the list directly.

This fix exposes a path where such functions are produced in the
outliner in the wrong mode; requiring a fix there to correctly drop
RemoveDIs-mode debug-info. This is covered by
test/DebugInfo/AArch64/ir-outliner.ll
  • Loading branch information
jmorse committed Feb 20, 2024
1 parent ababa96 commit 3e76e60
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 3 additions & 1 deletion llvm/lib/IR/Function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,10 @@ Function::Function(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace,
if (Ty->getNumParams())
setValueSubclassData(1); // Set the "has lazy arguments" bit.

if (ParentModule)
if (ParentModule) {
ParentModule->getFunctionList().push_back(this);
IsNewDbgInfoFormat = ParentModule->IsNewDbgInfoFormat;
}

HasLLVMReservedName = getName().starts_with("llvm.");
// Ensure intrinsics have the right parameter attributes.
Expand Down
11 changes: 7 additions & 4 deletions llvm/lib/Transforms/IPO/IROutliner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,12 @@ static void moveFunctionData(Function &Old, Function &New,
std::vector<Instruction *> DebugInsts;

for (Instruction &Val : CurrBB) {
// Since debug-info originates from many different locations in the
// program, it will cause incorrect reporting from a debugger if we keep
// the same debug instructions. Drop non-intrinsic DPValues here,
// collect intrinsics for removal later.
Val.dropDbgValues();

// We must handle the scoping of called functions differently than
// other outlined instructions.
if (!isa<CallInst>(&Val)) {
Expand All @@ -744,10 +750,7 @@ static void moveFunctionData(Function &Old, Function &New,
// From this point we are only handling call instructions.
CallInst *CI = cast<CallInst>(&Val);

// We add any debug statements here, to be removed after. Since the
// instructions originate from many different locations in the program,
// it will cause incorrect reporting from a debugger if we keep the
// same debug instructions.
// Collect debug intrinsics for later removal.
if (isa<DbgInfoIntrinsic>(CI)) {
DebugInsts.push_back(&Val);
continue;
Expand Down

0 comments on commit 3e76e60

Please sign in to comment.