problems running JIT code on Mac 32-bit

Hello,

I am trying to run this test program via JIT on my Mac (10.7.1) where I have compiled the latest LLVM code for 32-bit and it is not working properly. Running the same code against LLVM 2.9 works fine. I also tried recompiling my same checkout of LLVM as 64-bit and re-compiled my test program and that works fine, for some reason the 32-bit version is yielding unexpected behavior. I believe I am linking with all of the required LLVM .a files. Here’s my code:

#include

#include “llvm/LLVMContext.h”

#include “llvm/Module.h”

#include “llvm/Constants.h”

#include “llvm/DerivedTypes.h”

#include “llvm/Instructions.h”

#include “llvm/ExecutionEngine/JIT.h”

#include “llvm/ExecutionEngine/Interpreter.h”

#include “llvm/ExecutionEngine/GenericValue.h”

#include “llvm/Support/TargetSelect.h”

#include “llvm/Support/ManagedStatic.h”

#include “llvm/Support/raw_ostream.h”

#include “llvm/Support/IRBuilder.h”

using namespace std;

using namespace llvm;

int main(int argc, char** argv){

InitializeNativeTarget();

LLVMContext context;

Module* module = new Module(“test”, context);

vector<Type*> args;

args.push_back(Type::getInt32Ty(context));

FunctionType* ft = FunctionType::get(Type::getInt32Ty(context),

args, false);

Function* f = Function::Create(ft,

GlobalValue::ExternalLinkage,

“f”, module);

Value* arg = f->arg_begin();

BasicBlock* bb = BasicBlock::Create(context, “entry”, f);

IRBuilder<> builder(bb);

Value* one = builder.getInt32(1);

Value* v = builder.CreateAdd(one, arg);

builder.CreateRet(v);

ExecutionEngine* engine = EngineBuilder(module).create();

void* vpf = engine->getPointerToFunction(f);

int32_t (*fp)(int32_t) =

(int32_t (*)(int32_t))(intptr_t)vpf;

int32_t out = fp(10);

cout << "out is: " << out << endl;

return 0;

}

I appreciate your help. Thanks,

Nick

I can duplicate this and a quick look shows that at one point we’re passing the argument on the stack and then expecting it in a different location. A bug filed about this when I can take some more time to look at it would be good.

Thanks!

-eric