[ManagedMemoryRewrite] Make pass more robust and fix memory issue

Instead of using Twines and temporary expressions, we do string manipulation
through a std::string. This resolves a memory corruption issue, which likely
was caused by twines loosing their underlying string too soon.

llvm-svn: 311264
This commit is contained in:
Tobias Grosser 2017-08-19 23:03:45 +00:00
parent a0319bb434
commit 9041118983
1 changed files with 4 additions and 2 deletions

View File

@ -218,13 +218,15 @@ replaceGlobalArray(Module &M, const DataLayout &DL, GlobalVariable &Array,
// At this point, we have committed to replacing this array.
ReplacedGlobals.insert(&Array);
std::string NewName = (Array.getName() + Twine(".toptr")).str();
std::string NewName = Array.getName();
NewName += ".toptr";
GlobalVariable *ReplacementToArr =
cast<GlobalVariable>(M.getOrInsertGlobal(NewName, ElemPtrTy));
ReplacementToArr->setInitializer(ConstantPointerNull::get(ElemPtrTy));
Function *PollyMallocManaged = getOrCreatePollyMallocManaged(M);
Twine FnName = Array.getName() + ".constructor";
std::string FnName = Array.getName();
FnName += ".constructor";
PollyIRBuilder Builder(M.getContext());
FunctionType *Ty = FunctionType::get(Builder.getVoidTy(), false);
const GlobalValue::LinkageTypes Linkage = Function::ExternalLinkage;