summaryrefslogtreecommitdiffstats
path: root/llvm/lib/ExecutionEngine/Interpreter
diff options
context:
space:
mode:
authorGabor Greif <ggreif@gmail.com>2007-10-11 19:40:35 +0000
committerGabor Greif <ggreif@gmail.com>2007-10-11 19:40:35 +0000
commitcb6832efe0eb35303928068d91ec1d5823e25a0a (patch)
treedd1c2af2f7e9960a0892238825c0b24efa253e7c /llvm/lib/ExecutionEngine/Interpreter
parent9ccea99165d2e5cb4fba57b0d02e56651e2ae28c (diff)
downloadbcm5719-llvm-cb6832efe0eb35303928068d91ec1d5823e25a0a.tar.gz
bcm5719-llvm-cb6832efe0eb35303928068d91ec1d5823e25a0a.zip
Fix an assertion abort on sparc. malloc(0) is allowed to
return NULL. llvm-svn: 42871
Diffstat (limited to 'llvm/lib/ExecutionEngine/Interpreter')
-rw-r--r--llvm/lib/ExecutionEngine/Interpreter/Execution.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp b/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp
index 95e2143787c..f11cf816b22 100644
--- a/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp
+++ b/llvm/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);
OpenPOWER on IntegriCloud