summaryrefslogtreecommitdiffstats
path: root/polly/lib/CodeGen/RuntimeDebugBuilder.cpp
diff options
context:
space:
mode:
authorTobias Grosser <tobias@grosser.es>2015-11-05 19:43:34 +0000
committerTobias Grosser <tobias@grosser.es>2015-11-05 19:43:34 +0000
commit4bf262a0f207226c62b95ad774676157641b168a (patch)
treea07f7939c138813ca354ab585b88337669f79644 /polly/lib/CodeGen/RuntimeDebugBuilder.cpp
parent387e66e79fc368760418f7394a6e93eeeb3f0ec8 (diff)
downloadbcm5719-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.cpp14
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));
OpenPOWER on IntegriCloud