diff options
Diffstat (limited to 'clang/lib/CodeGen/CGDecl.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGDecl.cpp | 28 |
1 files changed, 1 insertions, 27 deletions
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index 882dbad..563f728 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -370,38 +370,12 @@ CodeGenFunction::AddInitializerToStaticVarDecl(const VarDecl &D, assert(VarSize == CstSize && "Emitted constant has unexpected size"); #endif - // The initializer may differ in type from the global. Rewrite - // the global to match the initializer. (We have to do this - // because some types, like unions, can't be completely represented - // in the LLVM type system.) - if (GV->getValueType() != Init->getType()) { - llvm::GlobalVariable *OldGV = GV; - - GV = new llvm::GlobalVariable( - CGM.getModule(), Init->getType(), OldGV->isConstant(), - OldGV->getLinkage(), Init, "", - /*InsertBefore*/ OldGV, OldGV->getThreadLocalMode(), - OldGV->getType()->getPointerAddressSpace()); - GV->setVisibility(OldGV->getVisibility()); - GV->setDSOLocal(OldGV->isDSOLocal()); - GV->setComdat(OldGV->getComdat()); - - // Steal the name of the old global - GV->takeName(OldGV); - - // Replace all uses of the old global with the new global - OldGV->replaceAllUsesWith(GV); - - // Erase the old global, since it is no longer used. - OldGV->eraseFromParent(); - } - bool NeedsDtor = D.needsDestruction(getContext()) == QualType::DK_cxx_destructor; GV->setConstant( D.getType().isConstantStorage(getContext(), true, !NeedsDtor)); - GV->setInitializer(Init); + GV->replaceInitializer(Init); emitter.finalize(GV); |