Skip to content

Commit

Permalink
Revert "Strip debug info when inlining into a nodebug function."
Browse files Browse the repository at this point in the history
This reverts commit r296488.

As noted by David Blaikie on llvm-commits, I overlooked the case of a
debug function being inlined into a nodebug function being inlined
into a debug function.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297163 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
adrian-prantl committed Mar 7, 2017
1 parent 6494556 commit 378f96b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 70 deletions.
42 changes: 12 additions & 30 deletions lib/Transforms/Utils/InlineFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1343,26 +1343,22 @@ static bool allocaWouldBeStaticInEntry(const AllocaInst *AI ) {
return isa<Constant>(AI->getArraySize()) && !AI->isUsedWithInAlloca();
}

/// Update inlined instructions' line numbers to to encode location where these
/// instructions are inlined. Also strip all debug intrinsics that were inlined
/// into a nodebug function; there is no debug info the backend could produce
/// for a function without a DISubprogram attachment.
static void fixupDebugInfo(Function *Fn, Function::iterator FI,
Instruction *TheCall, bool CalleeHasDebugInfo) {
bool CallerHasDebugInfo = Fn->getSubprogram();
bool StripDebugInfo = !CallerHasDebugInfo && CalleeHasDebugInfo;
SmallVector<DbgInfoIntrinsic *, 8> IntrinsicsToErase;
/// Update inlined instructions' line numbers to
/// to encode location where these instructions are inlined.
static void fixupLineNumbers(Function *Fn, Function::iterator FI,
Instruction *TheCall, bool CalleeHasDebugInfo) {
const DebugLoc &TheCallDL = TheCall->getDebugLoc();
if (!TheCallDL)
return;

auto &Ctx = Fn->getContext();
DILocation *InlinedAtNode = nullptr;
DILocation *InlinedAtNode = TheCallDL;

// Create a unique call site, not to be confused with any other call from the
// same location.
if (TheCallDL)
InlinedAtNode = DILocation::getDistinct(
Ctx, TheCallDL->getLine(), TheCallDL->getColumn(),
TheCallDL->getScope(), TheCallDL->getInlinedAt());
InlinedAtNode = DILocation::getDistinct(
Ctx, InlinedAtNode->getLine(), InlinedAtNode->getColumn(),
InlinedAtNode->getScope(), InlinedAtNode->getInlinedAt());

// Cache the inlined-at nodes as they're built so they are reused, without
// this every instruction's inlined-at chain would become distinct from each
Expand All @@ -1372,17 +1368,6 @@ static void fixupDebugInfo(Function *Fn, Function::iterator FI,
for (; FI != Fn->end(); ++FI) {
for (BasicBlock::iterator BI = FI->begin(), BE = FI->end();
BI != BE; ++BI) {
if (StripDebugInfo) {
// Inlining into a nodebug function.
if (auto *DI = dyn_cast<DbgInfoIntrinsic>(BI))
// Mark dead debug intrinsics for deletion.
IntrinsicsToErase.push_back(DI);
else
// Remove the dangling debug location.
BI->setDebugLoc(DebugLoc());
continue;
}

if (DebugLoc DL = BI->getDebugLoc()) {
BI->setDebugLoc(
updateInlinedAtInfo(DL, InlinedAtNode, BI->getContext(), IANodes));
Expand All @@ -1405,9 +1390,6 @@ static void fixupDebugInfo(Function *Fn, Function::iterator FI,
BI->setDebugLoc(TheCallDL);
}
}

for (auto *DI : IntrinsicsToErase)
DI->eraseFromParent();
}
/// Update the block frequencies of the caller after a callee has been inlined.
///
Expand Down Expand Up @@ -1728,8 +1710,8 @@ bool llvm::InlineFunction(CallSite CS, InlineFunctionInfo &IFI,
// For 'nodebug' functions, the associated DISubprogram is always null.
// Conservatively avoid propagating the callsite debug location to
// instructions inlined from a function whose DISubprogram is not null.
fixupDebugInfo(Caller, FirstNewBlock, TheCall,
CalledFunc->getSubprogram() != nullptr);
fixupLineNumbers(Caller, FirstNewBlock, TheCall,
CalledFunc->getSubprogram() != nullptr);

// Clone existing noalias metadata if necessary.
CloneAliasScopeMetadata(CS, VMap);
Expand Down
7 changes: 3 additions & 4 deletions test/Transforms/Inline/local-as-metadata-undominated-use.ll
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ entry:
}

; CHECK-LABEL: define i32 @caller(
define i32 @caller(i32 %i) !dbg !3 {
define i32 @caller(i32 %i) {
; CHECK-NEXT: entry:
entry:
; Although the inliner shouldn't crash, it can't be expected to get the
; "correct" SSA value since its assumptions have been violated.
; CHECK-NEXT: tail call void @llvm.dbg.value(metadata ![[EMPTY:[0-9]+]],
; CHECK-NEXT: %{{.*}} = add nsw
%call = tail call i32 @foo(i32 %i), !dbg !14
%call = tail call i32 @foo(i32 %i)
ret i32 %call
}

Expand All @@ -34,9 +34,9 @@ declare void @llvm.dbg.value(metadata, i64, metadata, metadata)

!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.9.0 (trunk 265634) (llvm/trunk 265637)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
!1 = !DIFile(filename: "t.c", directory: "/path/to/tests")

; CHECK: ![[EMPTY]] = !{}
!2 = !{}
!3 = distinct !DISubprogram(name: "caller", scope: !1, file: !1, line: 3, type: !5, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: true, unit: !0)
!4 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 2, type: !5, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: true, unit: !0)
!5 = !DISubroutineType(types: !6)
!6 = !{!7, !7}
Expand All @@ -47,4 +47,3 @@ declare void @llvm.dbg.value(metadata, i64, metadata, metadata)
!11 = !DILocation(line: 2, column: 13, scope: !4)
!12 = !DILocation(line: 2, column: 27, scope: !4)
!13 = !DILocation(line: 2, column: 18, scope: !4)
!14 = !DILocation(line: 3, scope: !3)
36 changes: 0 additions & 36 deletions test/Transforms/Inline/nodebug.ll

This file was deleted.

0 comments on commit 378f96b

Please sign in to comment.