Skip to content

Commit 6956811

Browse files
committed
Merge Ctors from nested transactions.
We cannot run nested transactions' initializations until the parent is done. But the parent transaction must not replace the nested transactions' static initialization either. The only way out is to collapse all transactions' static initializers until they are run. This fixes root [0] TTree *chain = new TTree("abc","title") which left chain == 0 before.
1 parent 00f3696 commit 6956811

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

interpreter/llvm/src/tools/clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,8 @@ void CodeGenModule::AddGlobalDtor(llvm::Function * Dtor, int Priority) {
493493
}
494494

495495
void CodeGenModule::EmitCtorList(CtorList &Fns, const char *GlobalName) {
496+
if (Fns.empty())
497+
return;
496498
// Ctor function type is void()*.
497499
llvm::FunctionType* CtorFTy = llvm::FunctionType::get(VoidTy, false);
498500
llvm::Type *CtorPFTy = llvm::PointerType::getUnqual(CtorFTy);
@@ -501,8 +503,23 @@ void CodeGenModule::EmitCtorList(CtorList &Fns, const char *GlobalName) {
501503
llvm::StructType *CtorStructTy =
502504
llvm::StructType::get(Int32Ty, llvm::PointerType::getUnqual(CtorFTy), NULL);
503505

506+
504507
// Construct the constructor and destructor arrays.
505508
SmallVector<llvm::Constant*, 8> Ctors;
509+
510+
// Add existing ones:
511+
if (llvm::GlobalVariable* OldGlobal
512+
= TheModule.getGlobalVariable(GlobalName, true)) {
513+
if (const llvm::ConstantArray* CArr =
514+
llvm::dyn_cast<llvm::ConstantArray>(OldGlobal->getInitializer())) {
515+
uint64_t OldSize = CArr->getType()->getNumElements();
516+
for (uint64_t Idx = 0; Idx < OldSize; ++Idx) {
517+
Ctors.push_back(CArr->getAggregateElement(Idx));
518+
}
519+
}
520+
OldGlobal->eraseFromParent();
521+
}
522+
506523
for (CtorList::const_iterator I = Fns.begin(), E = Fns.end(); I != E; ++I) {
507524
llvm::Constant *S[] = {
508525
llvm::ConstantInt::get(Int32Ty, I->second, false),

0 commit comments

Comments
 (0)