fix a tricky bug in the JIT global variable emitter, that was triggered when JITing...
[oota-llvm.git] / lib / VMCore / BasicBlock.cpp
index 15cc0d9e816664385bd8485db7f0128739cd6aa0..514aa1de237704547b52bbca636482c0c34b69d1 100644 (file)
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/BasicBlock.h"
 #include "llvm/Constants.h"
 #include "llvm/Instructions.h"
 #include "llvm/Type.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/CFG.h"
 #include "llvm/Support/LeakDetector.h"
 #include "llvm/Support/Compiler.h"
@@ -259,7 +261,9 @@ BasicBlock *BasicBlock::splitBasicBlock(iterator I, const std::string &BBName) {
   assert(I != InstList.end() &&
          "Trying to get me to create degenerate basic block!");
 
-  BasicBlock *New = BasicBlock::Create(BBName, getParent(), getNext());
+  BasicBlock *InsertBefore = next(Function::iterator(this))
+                               .getNodePtrUnchecked();
+  BasicBlock *New = BasicBlock::Create(BBName, getParent(), InsertBefore);
 
   // Move all of the specified instructions from the original basic block into
   // the new basic block.