Skip to content

Commit 285d3e9

Browse files
committed
[CloneFunction][DebugInfo] Ensure DILocalVariables of inlined functions are not cloned (NFC)
This change was separated from llvm#119001. When cloning functions, use IdentityMDPredicate to ensure that if DISubprogram is not cloned, then its DILocalVariables are not cloned either. This is expected to be an NFC currently, as DILocalVariables only reference their subprograms (via DILocalScopes) and types. Since inlined DISubprograms and DITypes are not cloned during the process, DILocalVariables are mapped to self in ValueMapper (in mapTopLevelUniquedNode). However, it will be needed for the original PR llvm#119001, where it is possible that the type of a DILocalVariable is cloned if it lies in the scope of a DISubprogram that is being cloned, whereas the DILocalVariable itself belongs to a different DISubprogram. I'm making this change into a separate PR to make the original PR a bit smaller, and since this has more to do with variables than with types.
1 parent 4418a8e commit 285d3e9

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

llvm/lib/Transforms/Utils/CloneFunction.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,28 @@ MetadataPredicate createIdentityMDPredicate(const Function &F,
5959
return [](const Metadata *MD) { return false; };
6060

6161
DISubprogram *SPClonedWithinModule = F.getSubprogram();
62+
63+
// Don't clone inlined subprograms.
64+
auto ShouldKeep = [SPClonedWithinModule](const DISubprogram *SP) -> bool {
65+
return SP != SPClonedWithinModule;
66+
};
67+
6268
return [=](const Metadata *MD) {
6369
// Avoid cloning types, compile units, and (other) subprograms.
6470
if (isa<DICompileUnit>(MD) || isa<DIType>(MD))
6571
return true;
6672

6773
if (auto *SP = dyn_cast<DISubprogram>(MD))
68-
return SP != SPClonedWithinModule;
74+
return ShouldKeep(SP);
6975

7076
// If a subprogram isn't going to be cloned skip its lexical blocks as well.
7177
if (auto *LScope = dyn_cast<DILocalScope>(MD))
72-
return LScope->getSubprogram() != SPClonedWithinModule;
78+
return ShouldKeep(LScope->getSubprogram());
79+
80+
// Avoid cloning local variables of subprograms that won't be cloned.
81+
if (auto *DV = dyn_cast<DILocalVariable>(MD))
82+
if (auto *S = dyn_cast_or_null<DILocalScope>(DV->getScope()))
83+
return ShouldKeep(S->getSubprogram());
7384

7485
return false;
7586
};

0 commit comments

Comments
 (0)