[llvm-commits] ExecutionEngine/2003-01-15-AlignmentTest.ll asserts on SPARC
Chris Lattner
clattner at apple.com
Thu Oct 11 08:14:59 PDT 2007
On Oct 11, 2007, at 3:52 AM, Gabor Greif wrote:
> Hi all,
>
> I get an ugly interpreter failure:
The patch looks great to me, please apply! It would also be nice to
add a "// avoid calls of malloc(0)." comment before it,
-Chris
>
>
>
> Test Run By ggreif on Thu Oct 11 12:41:31 2007
> Native configuration is sparc-sun-solaris2.9
>
> === ExecutionEngine tests ===
>
> Schedule of variations:
> unix
>
> Running target unix
> Using /home/ggreif/share/dejagnu/baseboards/unix.exp as board
> description file for target.
> Using /home/ggreif/share/dejagnu/config/unix.exp as generic
> interface file for target.
> WARNING: Couldn't find tool config file for unix, using default.
> Running /home/ggreif/llvm/test/ExecutionEngine/dg.exp ...
> FAIL: /home/ggreif/llvm/test/ExecutionEngine/2003-01-15-
> AlignmentTest.ll
> Failed with signal(SIGABRT) at line 2
> while running: lli 2003-01-15-AlignmentTest.ll.tmp.bc > /dev/null
> Assertion failed: Result.PointerVal != 0 && "Null pointer returned
> by malloc!", file Execution.cpp, line 761
>
>
> === ExecutionEngine Summary ===
>
> # of expected passes 38
> # of unexpected failures 1
> make[1]: *** [check-local] Error 1
> make[1]: Leaving directory `/home/ggreif/llvm/test'
> make: *** [check] Error 2
>
>
>
> The problem comes from allocating a zero sized array,
> and actually I think malloc is allowed to return NULL
> on a call to malloc(0):
>
>
>
> ggreif at my [!187] cat /home/ggreif/llvm/test/ExecutionEngine/
> 2003-01-15-AlignmentTest.ll
> ; RUN: llvm-upgrade %s | llvm-as -f -o %t.bc
> ; RUN: lli %t.bc > /dev/null
>
>
> int %bar(sbyte* %X) {
> %P = alloca double ; pointer should be 4 byte aligned!
> %R = cast double* %P to int
> %A = and int %R, 3
> ret int %A
> }
>
> int %main() {
> %SP = alloca sbyte
> %X = add uint 0, 0
> alloca sbyte, uint %X ; <<<<<<< Results in malloc(0) !!!!
>
> call int %bar(sbyte* %SP)
> ret int %0
> }
>
>
> Using this patch:
>
> ggreif at my [!190] svn diff lib/ExecutionEngine/Interpreter/
> Execution.cpp
> Index: lib/ExecutionEngine/Interpreter/Execution.cpp
> ===================================================================
> --- lib/ExecutionEngine/Interpreter/Execution.cpp (revision
> 42860)
> +++ lib/ExecutionEngine/Interpreter/Execution.cpp (working copy)
> @@ -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,7 @@
>
> unsigned TypeSize = (size_t)TD.getTypeSize(Ty);
>
> - unsigned MemToAlloc = NumElements * TypeSize;
> + unsigned MemToAlloc = std::max(1U, NumElements * TypeSize);
>
> // Allocate enough memory to hold the type...
> void *Memory = malloc(MemToAlloc);
>
>
>
> the problem goes away.
>
> I am not sure whether this is an acceptable patch
> or we should find a more performant one :-)
>
> Cheers,
>
> Gabor
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list