aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/ModuleUtils.cpp
diff options
context:
space:
mode:
authorTeresa Johnson <tejohnson@google.com>2021-02-18 17:23:02 -0800
committerTeresa Johnson <tejohnson@google.com>2021-02-20 09:46:43 -0800
commitfde55a9c9bf147241249ae478760ae69dd1925ed (patch)
tree3ecf62a3b0dda9ff8e24951d4271f2773a6ce603 /llvm/lib/Transforms/Utils/ModuleUtils.cpp
parent309b00a42e902e816dad03c2c2f1a9e41ba130bc (diff)
downloadllvm-fde55a9c9bf147241249ae478760ae69dd1925ed.zip
llvm-fde55a9c9bf147241249ae478760ae69dd1925ed.tar.gz
llvm-fde55a9c9bf147241249ae478760ae69dd1925ed.tar.bz2
[LTO] Fix cloning of llvm*.used when splitting module
Refines the fix in 3c4c205060c9398da705eb71b63ddd8a04999de9 to only put globals whose defs were cloned into the split regular LTO module on the cloned llvm*.used globals. This avoids an issue where one of the attached values was a local that was promoted in the original module after the module was cloned. We only need to have the values defined in the new module on those globals. Fixes PR49251. Differential Revision: https://reviews.llvm.org/D97013
Diffstat (limited to 'llvm/lib/Transforms/Utils/ModuleUtils.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/ModuleUtils.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/Utils/ModuleUtils.cpp b/llvm/lib/Transforms/Utils/ModuleUtils.cpp
index ef9f18a..f7bd8f0 100644
--- a/llvm/lib/Transforms/Utils/ModuleUtils.cpp
+++ b/llvm/lib/Transforms/Utils/ModuleUtils.cpp
@@ -76,11 +76,13 @@ static void appendToUsedList(Module &M, StringRef Name, ArrayRef<GlobalValue *>
SmallPtrSet<Constant *, 16> InitAsSet;
SmallVector<Constant *, 16> Init;
if (GV) {
- auto *CA = cast<ConstantArray>(GV->getInitializer());
- for (auto &Op : CA->operands()) {
- Constant *C = cast_or_null<Constant>(Op);
- if (InitAsSet.insert(C).second)
- Init.push_back(C);
+ if (GV->hasInitializer()) {
+ auto *CA = cast<ConstantArray>(GV->getInitializer());
+ for (auto &Op : CA->operands()) {
+ Constant *C = cast_or_null<Constant>(Op);
+ if (InitAsSet.insert(C).second)
+ Init.push_back(C);
+ }
}
GV->eraseFromParent();
}