浏览代码

BrainF example: fixing segfault caused by outdated code with missing MCJIT dependency
Differential Revision: https://reviews.llvm.org/D26280

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289857 91177308-0d34-0410-b5e6-96231b3b80d8

Boris Ulasevich 8 年之前
父节点
当前提交
0eeb59d037
共有 2 个文件被更改,包括 7 次插入0 次删除
  1. 6 0
      examples/BrainF/BrainFDriver.cpp
  2. 1 0
      examples/BrainF/CMakeLists.txt

+ 6 - 0
examples/BrainF/BrainFDriver.cpp

@@ -29,6 +29,7 @@
 #include "llvm/Bitcode/BitcodeWriter.h"
 #include "llvm/ExecutionEngine/ExecutionEngine.h"
 #include "llvm/ExecutionEngine/GenericValue.h"
+#include "llvm/ExecutionEngine/MCJIT.h"
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DerivedTypes.h"
@@ -153,10 +154,15 @@ int main(int argc, char **argv) {
   //Write it out
   if (JIT) {
     InitializeNativeTarget();
+    InitializeNativeTargetAsmPrinter();
 
     outs() << "------- Running JIT -------\n";
     Module &M = *Mod;
     ExecutionEngine *ee = EngineBuilder(std::move(Mod)).create();
+    if (!ee) {
+      errs() << "Error: execution engine creation failed.\n";
+      abort();
+    }
     std::vector<GenericValue> args;
     Function *brainf_func = M.getFunction("brainf");
     GenericValue gv = ee->runFunction(brainf_func, args);

+ 1 - 0
examples/BrainF/CMakeLists.txt

@@ -3,6 +3,7 @@ set(LLVM_LINK_COMPONENTS
   Core
   ExecutionEngine
   MC
+  MCJIT
   Support
   nativecodegen
   )