diff options
| author | Gabor Greif <ggreif@gmail.com> | 2007-10-11 19:40:35 +0000 |
|---|---|---|
| committer | Gabor Greif <ggreif@gmail.com> | 2007-10-11 19:40:35 +0000 |
| commit | cb6832efe0eb35303928068d91ec1d5823e25a0a (patch) | |
| tree | dd1c2af2f7e9960a0892238825c0b24efa253e7c /llvm/lib/ExecutionEngine/Interpreter/Execution.cpp | |
| parent | 9ccea99165d2e5cb4fba57b0d02e56651e2ae28c (diff) | |
| download | llvm-cb6832efe0eb35303928068d91ec1d5823e25a0a.zip llvm-cb6832efe0eb35303928068d91ec1d5823e25a0a.tar.gz llvm-cb6832efe0eb35303928068d91ec1d5823e25a0a.tar.bz2 | |
Fix an assertion abort on sparc. malloc(0) is allowed to
return NULL.
llvm-svn: 42871
Diffstat (limited to 'llvm/lib/ExecutionEngine/Interpreter/Execution.cpp')
| -rw-r--r-- | llvm/lib/ExecutionEngine/Interpreter/Execution.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp b/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp index 95e2143..f11cf81 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); |
