Skip to content

Commit 47144a0

Browse files
authored
[CloneFunction][DebugInfo] Ensure DILocalVariables of inlined functions are not cloned (NFC) (#138590)
This change was separated from #119001. When cloning functions, use IdentityMDPredicate to ensure that if DISubprogram is not cloned, then its DILocalVariables are not cloned either. This is currently expected to be an NFC, as DILocalVariables only reference their subprograms (via DILocalScopes) and types, and inlined DISubprograms and DITypes are not cloned. Thus, DILocalVariables are mapped to self in ValueMapper (in mapTopLevelUniquedNode). However, it will be needed for the original PR #119001, where a DILocalVariable may refer to a local type of a DISubprogram that is being cloned. In that case, ValueMapper will clone DILocalVariable even if it belongs to an inlined DISubprogram that is not cloned, which should be avoided. I'm making this change into a separate PR to make the original PR a bit smaller, and because this has more to do with variables than with types.
1 parent 80fa621 commit 47144a0

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
@@ -81,17 +81,28 @@ MetadataPredicate createIdentityMDPredicate(const Function &F,
8181
return [](const Metadata *MD) { return false; };
8282

8383
DISubprogram *SPClonedWithinModule = F.getSubprogram();
84+
85+
// Don't clone inlined subprograms.
86+
auto ShouldKeep = [SPClonedWithinModule](const DISubprogram *SP) -> bool {
87+
return SP != SPClonedWithinModule;
88+
};
89+
8490
return [=](const Metadata *MD) {
8591
// Avoid cloning types, compile units, and (other) subprograms.
8692
if (isa<DICompileUnit>(MD) || isa<DIType>(MD))
8793
return true;
8894

8995
if (auto *SP = dyn_cast<DISubprogram>(MD))
90-
return SP != SPClonedWithinModule;
96+
return ShouldKeep(SP);
9197

9298
// If a subprogram isn't going to be cloned skip its lexical blocks as well.
9399
if (auto *LScope = dyn_cast<DILocalScope>(MD))
94-
return LScope->getSubprogram() != SPClonedWithinModule;
100+
return ShouldKeep(LScope->getSubprogram());
101+
102+
// Avoid cloning local variables of subprograms that won't be cloned.
103+
if (auto *DV = dyn_cast<DILocalVariable>(MD))
104+
if (auto *S = dyn_cast_or_null<DILocalScope>(DV->getScope()))
105+
return ShouldKeep(S->getSubprogram());
95106

96107
return false;
97108
};

0 commit comments

Comments
 (0)