[LLVMdev] problems running JIT code on Mac 32-bit

Nick Walters nickwalters99 at gmail.com
Wed Oct 12 21:24:29 PDT 2011


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 <iostream>

#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){


  LLVMContext context;

  Module* module = new Module("test", context);

  vector<Type*> args;


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

       args, false);

  Function* f = Function::Create(ft,


 "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);


  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,

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111012/5223adb6/attachment.html>

More information about the llvm-dev mailing list