diff options
author | Tobias Grosser <tobias@grosser.es> | 2015-11-05 19:43:34 +0000 |
---|---|---|
committer | Tobias Grosser <tobias@grosser.es> | 2015-11-05 19:43:34 +0000 |
commit | 4bf262a0f207226c62b95ad774676157641b168a (patch) | |
tree | a07f7939c138813ca354ab585b88337669f79644 /polly/lib/CodeGen/RuntimeDebugBuilder.cpp | |
parent | 387e66e79fc368760418f7394a6e93eeeb3f0ec8 (diff) | |
download | bcm5719-llvm-4bf262a0f207226c62b95ad774676157641b168a.tar.gz bcm5719-llvm-4bf262a0f207226c62b95ad774676157641b168a.zip |
RunTimeDebugBuilder: Allocate memory _after_ knowing how much is needed
This fixes a memory corruption issue, where we accessed more memory than
actually allocated.
llvm-svn: 252197
Diffstat (limited to 'polly/lib/CodeGen/RuntimeDebugBuilder.cpp')
-rw-r--r-- | polly/lib/CodeGen/RuntimeDebugBuilder.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/polly/lib/CodeGen/RuntimeDebugBuilder.cpp b/polly/lib/CodeGen/RuntimeDebugBuilder.cpp index dd2432ad31d..29f113dbd0c 100644 --- a/polly/lib/CodeGen/RuntimeDebugBuilder.cpp +++ b/polly/lib/CodeGen/RuntimeDebugBuilder.cpp @@ -163,20 +163,20 @@ void RuntimeDebugBuilder::createGPUPrinterT(PollyIRBuilder &Builder, ArrayRef<Value *> Values) { std::string str; - // Allocate print buffer (assuming 2*32 bit per element) - auto T = ArrayType::get(Builder.getInt32Ty(), Values.size() * 2); - Value *Data = new AllocaInst( - T, "polly.vprint.buffer", - Builder.GetInsertBlock()->getParent()->getEntryBlock().begin()); - auto *Zero = Builder.getInt64(0); - auto *DataPtr = Builder.CreateGEP(Data, {Zero, Zero}); auto ToPrint = getGPUThreadIdentifiers(Builder); ToPrint.push_back(Builder.CreateGlobalStringPtr("\n ", "", 4)); ToPrint.insert(ToPrint.end(), Values.begin(), Values.end()); + // Allocate print buffer (assuming 2*32 bit per element) + auto T = ArrayType::get(Builder.getInt32Ty(), ToPrint.size() * 2); + Value *Data = new AllocaInst( + T, "polly.vprint.buffer", + Builder.GetInsertBlock()->getParent()->getEntryBlock().begin()); + auto *DataPtr = Builder.CreateGEP(Data, {Zero, Zero}); + int Offset = 0; for (auto Val : ToPrint) { auto Ptr = Builder.CreateGEP(DataPtr, Builder.getInt64(Offset)); |