aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ExecutionEngine
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
commit7ee10f95c0f7990e110e775be7fa47fca3637fe3 (patch)
tree9b90f7bbd003847eedf1ab809247c54c5e4aba69 /lib/ExecutionEngine
parente2d6bbb00da7530c4f8846774bfeddeef56f66ed (diff)
downloadexternal_llvm-7ee10f95c0f7990e110e775be7fa47fca3637fe3.zip
external_llvm-7ee10f95c0f7990e110e775be7fa47fca3637fe3.tar.gz
external_llvm-7ee10f95c0f7990e110e775be7fa47fca3637fe3.tar.bz2
Fix an assertion abort on sparc. malloc(0) is allowed to
return NULL. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42871 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine')
-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 95e2143..f11cf81 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);