aboutsummaryrefslogtreecommitdiff
path: root/lib/ExecutionEngine/Interpreter/Execution.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ExecutionEngine/Interpreter/Execution.cpp')
-rw-r--r--lib/ExecutionEngine/Interpreter/Execution.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/ExecutionEngine/Interpreter/Execution.cpp b/lib/ExecutionEngine/Interpreter/Execution.cpp
index 95e2143787..f11cf816b2 100644
--- a/lib/ExecutionEngine/Interpreter/Execution.cpp
+++ b/lib/ExecutionEngine/Interpreter/Execution.cpp
@@ -24,6 +24,7 @@
#include "llvm/Support/Debug.h"
#include "llvm/Support/MathExtras.h"
#include <cmath>
+#include <algorithm>
using namespace llvm;
STATISTIC(NumDynamicInsts, "Number of dynamic instructions executed");
@@ -747,7 +748,8 @@ void Interpreter::visitAllocationInst(AllocationInst &I) {
unsigned TypeSize = (size_t)TD.getTypeSize(Ty);
- unsigned MemToAlloc = NumElements * TypeSize;
+ // Avoid malloc-ing zero bytes, use max()...
+ unsigned MemToAlloc = std::max(1U, NumElements * TypeSize);
// Allocate enough memory to hold the type...
void *Memory = malloc(MemToAlloc);