<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana">Hello,</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana">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:</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana; min-height: 16.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana">#include <iostream></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana; min-height: 16.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana">#include "llvm/LLVMContext.h"</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana">#include "llvm/Module.h"</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana">#include "llvm/Constants.h"</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana">#include "llvm/DerivedTypes.h"</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana">#include "llvm/Instructions.h"</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana">#include "llvm/ExecutionEngine/JIT.h"</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana">#include "llvm/ExecutionEngine/Interpreter.h"</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana">#include "llvm/ExecutionEngine/GenericValue.h"</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana">#include "llvm/Support/TargetSelect.h"</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana">#include "llvm/Support/ManagedStatic.h"</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana">#include "llvm/Support/raw_ostream.h"</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana">#include "llvm/Support/IRBuilder.h"</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana; min-height: 16.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana">using namespace std;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana">using namespace llvm;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana; min-height: 16.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana">int main(int argc, char** argv){</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana"> InitializeNativeTarget();</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana; min-height: 16.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana"> LLVMContext context;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana; min-height: 16.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana"> Module* module = new Module("test", context);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana; min-height: 16.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana"> vector<Type*> args;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana"> args.push_back(Type::getInt32Ty(context));</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana; min-height: 16.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana"> FunctionType* ft = FunctionType::get(Type::getInt32Ty(context),</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana"><span class="Apple-tab-span" style="white-space:pre"> </span> args, false);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana; min-height: 16.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana"> Function* f = Function::Create(ft,</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana"><span class="Apple-tab-span" style="white-space:pre"> </span> GlobalValue::ExternalLinkage,</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana"><span class="Apple-tab-span" style="white-space:pre"> </span> "f", module);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana; min-height: 16.0px"> </p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana"> Value* arg = f->arg_begin();</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana; min-height: 16.0px"> </p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana"> BasicBlock* bb = BasicBlock::Create(context, "entry", f);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana; min-height: 16.0px"> </p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana"> IRBuilder<> builder(bb);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana; min-height: 16.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana"> Value* one = builder.getInt32(1);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana; min-height: 16.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana"> Value* v = builder.CreateAdd(one, arg);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana"> builder.CreateRet(v);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana; min-height: 16.0px"> </p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana"> ExecutionEngine* engine = EngineBuilder(module).create();</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana; min-height: 16.0px"> </p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana"> void* vpf = engine->getPointerToFunction(f);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana; min-height: 16.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana"> int32_t (*fp)(int32_t) = </p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana"> (int32_t (*)(int32_t))(intptr_t)vpf;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana; min-height: 16.0px"> </p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana"> int32_t out = fp(10);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana; min-height: 16.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana"> cout << "out is: " << out << endl;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana; min-height: 16.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana"> return 0;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana; min-height: 16.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana">I appreciate your help. Thanks,</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana; min-height: 16.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana">Nick</p>