diff options
author | Vladislav Dzhidzhoev <vdzhidzhoev@accesssoftek.com> | 2024-01-11 17:08:12 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-11 17:08:12 +0100 |
commit | fc6faa1113e9069f41b5500db051210af0eea843 (patch) | |
tree | 105a76fe962bf21897f044fb563d7b5abd83a226 /llvm/lib/Transforms/Utils/CloneFunction.cpp | |
parent | 31ce0f1dda3caed829db09b9212eac54a8a28572 (diff) | |
download | llvm-fc6faa1113e9069f41b5500db051210af0eea843.zip llvm-fc6faa1113e9069f41b5500db051210af0eea843.tar.gz llvm-fc6faa1113e9069f41b5500db051210af0eea843.tar.bz2 |
[CloneFunction][DebugInfo] Avoid cloning DILocalVariables of inlined functions (#75385)
- [DebugMetadata][DwarfDebug] Support function-local types in lexical
block scopes (4/7)
- [CloneFunction][DebugInfo] Avoid cloning DILocalVariables of inlined
functions
This is a follow-up for https://reviews.llvm.org/D144006, fixing a crash
reported
in Chromium (https://reviews.llvm.org/D144006#4651955).
The first commit is added for convenience, as it has already been
accepted.
If DISubpogram was not cloned (e.g. we are cloning a function that has
other
functions inlined into it, and subprograms of the inlined functions are
not supposed to be cloned), it doesn't make sense to clone its
DILocalVariables as well.
Otherwise get duplicated DILocalVariables not tracked in their
subprogram's retainedNodes, that crash LTO with Chromium.
This is meant to be committed along with
https://reviews.llvm.org/D144006.
Diffstat (limited to 'llvm/lib/Transforms/Utils/CloneFunction.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/CloneFunction.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Utils/CloneFunction.cpp b/llvm/lib/Transforms/Utils/CloneFunction.cpp index c0f3333..2547ac0 100644 --- a/llvm/lib/Transforms/Utils/CloneFunction.cpp +++ b/llvm/lib/Transforms/Utils/CloneFunction.cpp @@ -232,12 +232,20 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc, // Avoid cloning types, compile units, and (other) subprograms. SmallPtrSet<const DISubprogram *, 16> MappedToSelfSPs; for (DISubprogram *ISP : DIFinder->subprograms()) { + // Don't clone inlined subprograms. if (ISP != SPClonedWithinModule) { mapToSelfIfNew(ISP); MappedToSelfSPs.insert(ISP); } } + // Avoid cloning local variables of subprograms that won't be cloned. + for (DILocalVariable *DV : DIFinder->local_variables()) + if (auto *S = dyn_cast_or_null<DILocalScope>(DV->getScope())) + if (DISubprogram *SP = S->getSubprogram()) + if (MappedToSelfSPs.contains(SP)) + mapToSelfIfNew(DV); + // If a subprogram isn't going to be cloned skip its lexical blocks as well. for (DIScope *S : DIFinder->scopes()) { auto *LScope = dyn_cast<DILocalScope>(S); @@ -249,7 +257,12 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc, mapToSelfIfNew(CU); for (DIType *Type : DIFinder->types()) - mapToSelfIfNew(Type); + // Don't skip subprogram's local types. + if (!isa_and_present<DILocalScope>(Type->getScope()) || + SPClonedWithinModule == nullptr || + dyn_cast<DILocalScope>(Type->getScope())->getSubprogram() != + SPClonedWithinModule) + mapToSelfIfNew(Type); } else { assert(!SPClonedWithinModule && "Subprogram should be in DIFinder->subprogram_count()..."); |