aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
authorMark Seaborn <mseaborn@chromium.org>2012-10-17 19:29:37 -0700
committerMark Seaborn <mseaborn@chromium.org>2012-10-17 19:29:37 -0700
commit19bfdca1e43752e134bafb3014508f66003b8873 (patch)
tree649ab98289c1d2793a8e65fe601895d8978d397d /lib/Transforms
parentb46cdaf9e7d5c0e0b6ba3b8cc20059525b7365aa (diff)
PNaCl: Fix nacl-expand-ctors pass to handle llvm.global_ctors being zeroinitializer
This case can happen if optimisation removes initializers. BUG=http://code.google.com/p/nativeclient/issues/detail?id=3018 TEST=test/Transforms/NaCl/expand-ctors-zeroinit.ll Review URL: https://codereview.chromium.org/11190028
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/NaCl/ExpandCtors.cpp34
1 files changed, 18 insertions, 16 deletions
diff --git a/lib/Transforms/NaCl/ExpandCtors.cpp b/lib/Transforms/NaCl/ExpandCtors.cpp
index 9c5f2cd2d7..6b8130e4fb 100644
--- a/lib/Transforms/NaCl/ExpandCtors.cpp
+++ b/lib/Transforms/NaCl/ExpandCtors.cpp
@@ -79,22 +79,24 @@ static void defineFuncArray(Module &M, const char *LlvmArrayName,
std::vector<Constant*> Funcs;
GlobalVariable *Array = M.getNamedGlobal(LlvmArrayName);
- if (Array && Array->hasInitializer()) {
- ConstantArray *InitList = cast<ConstantArray>(Array->getInitializer());
- std::vector<FuncArrayEntry> FuncsToSort;
- for (unsigned Index = 0; Index < InitList->getNumOperands(); ++Index) {
- ConstantStruct *CS = cast<ConstantStruct>(InitList->getOperand(Index));
- FuncArrayEntry Entry;
- Entry.priority = cast<ConstantInt>(CS->getOperand(0))->getZExtValue();
- Entry.func = CS->getOperand(1);
- FuncsToSort.push_back(Entry);
- }
-
- std::sort(FuncsToSort.begin(), FuncsToSort.end(), compareEntries);
- for (std::vector<FuncArrayEntry>::iterator Iter = FuncsToSort.begin();
- Iter != FuncsToSort.end();
- ++Iter) {
- Funcs.push_back(Iter->func);
+ if (Array) {
+ if (Array->hasInitializer() && !Array->getInitializer()->isNullValue()) {
+ ConstantArray *InitList = cast<ConstantArray>(Array->getInitializer());
+ std::vector<FuncArrayEntry> FuncsToSort;
+ for (unsigned Index = 0; Index < InitList->getNumOperands(); ++Index) {
+ ConstantStruct *CS = cast<ConstantStruct>(InitList->getOperand(Index));
+ FuncArrayEntry Entry;
+ Entry.priority = cast<ConstantInt>(CS->getOperand(0))->getZExtValue();
+ Entry.func = CS->getOperand(1);
+ FuncsToSort.push_back(Entry);
+ }
+
+ std::sort(FuncsToSort.begin(), FuncsToSort.end(), compareEntries);
+ for (std::vector<FuncArrayEntry>::iterator Iter = FuncsToSort.begin();
+ Iter != FuncsToSort.end();
+ ++Iter) {
+ Funcs.push_back(Iter->func);
+ }
}
// No code should be referencing global_ctors/global_dtors,
// because this symbol is internal to LLVM.