llvm interpreter cannot execute llvm-gcc generated bitcode

Hi!

We are compiling a very large C project in llvm and trying to execute
it in interpreter. There is a problem with executing the generated
bitcode.

We are using lli.exe and llvm-gcc.exe from official 2.6 LLVM release.

We have localized the problem to following c code:

Kristaps Straupe wrote:

Hi!

We are compiling a very large C project in llvm and trying to execute
it in interpreter. There is a problem with executing the generated
bitcode.

The interpreter is under-maintained in general, but this bug in particular is fixed SVN as-of r86428. Are you on a platform that isn't supported by llvm's jit?

Nick

Hi Kristaps,

Finally calling it with:
----------
llvm-gcc -c -emit-llvm -O2 a.c
lli -force-interpreter a.o
----------

Yields us:
-----------
"Assertion failed: width > BitWidth && "Invalid APInt ZeroExtend
request", file c:/proj/llvm/src/lib/Support/APInt.cpp, line 1064"
-----------
where both width and BitWidth have value "32".

I can't reproduce this with LLVM from subversion, so presumably it
has been fixed.

Ciao,

Duncan.

Hello again!

We have fetched the latest llvm sources from repository and the
original problem has went away. Though now we are facing a new problem
with interpreter on the following c code:

I think this doesn't work because libffi doesn't support vararg functions:
"There is no support for calling varargs functions. This may work on
some platforms, depending on how the ABI is defined, but it is not
reliable."

Since you are on a platform where the JIT doesn't work properly, I guess
libffi's varargs
don't work either. What platform is it?

This only refers to external varargs functions, not ones you define
yourself.
It works just fine with the JIT though.

I think it would be easier if you'd debug JIT problems this way (to
avoid running into libffi
limitations in the interpreter):
1. compile your code with -O0 to LLVM BC
2. compile the BC to native code (using llc + assembler + linker), test
that it works (output is correct)
3. use the JIT to run the BC, test that it works properly (output is
correct)
4. Repeat steps 1-3 with -O1, -O2, until it fails

Once you identified at which stage the problem occurs, you can try the
instructions here to further narrow down the problem:
http://llvm.org/docs/HowToSubmitABug.html#codegen

Best regards,
--Edwin

2010/2/1 Török Edwin <edwintorok@gmail.com>

Hello again!

We have fetched the latest llvm sources from repository and the
original problem has went away. Though now we are facing a new problem
with interpreter on the following c code:


#include <stdarg.h>
#include <stdio.h>

void doTheThing(int dummy, …)
{
va_list ap;
int z;

va_start(ap, dummy);
while( (z = va_arg(ap, int))!=0)
{
printf(“== %i ==\n”, z);
}
va_end(ap);
}

int main()
{
doTheThing(-1, 1, 2, 3, 0);
}

I think this doesn’t work because libffi doesn’t support vararg functions:
“There is no support for calling varargs functions. This may work on
some platforms, depending on how the ABI is defined, but it is not
reliable.”

I don’t think that’s the problem. The call to doTheThing shouldn’t involve libffi since it’s not an external call, and the call to printf doesn’t involve libffi since it’s a hard-coded known-varargs function. See the table at the end of lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp for a list of functions we trap instead of sending to libffi.

I have no idea why it’s failing yet.

Nick