[PATCH] D33269: MCJIT: add ProcessAllSections smoke test

Pavel Labath via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 17 02:20:48 PDT 2017


labath created this revision.
Herald added a subscriber: aprantl.

None of the existing MCJIT tests set ProcessAllSections to true or use
modules with debug info, so add a test to exercise these code paths.

This would have caught the bug fixed by r303239.


https://reviews.llvm.org/D33269

Files:
  unittests/ExecutionEngine/MCJIT/MCJITTest.cpp


Index: unittests/ExecutionEngine/MCJIT/MCJITTest.cpp
===================================================================
--- unittests/ExecutionEngine/MCJIT/MCJITTest.cpp
+++ unittests/ExecutionEngine/MCJIT/MCJITTest.cpp
@@ -12,9 +12,10 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "MCJITTestBase.h"
 #include "llvm/ExecutionEngine/MCJIT.h"
+#include "llvm/IR/DIBuilder.h"
 #include "llvm/Support/DynamicLibrary.h"
-#include "MCJITTestBase.h"
 #include "gtest/gtest.h"
 
 using namespace llvm;
@@ -281,4 +282,39 @@
   EXPECT_FALSE(std::find(I, E, "Foo2") == E);
 }
 
+static Function *insertMainWithDI(LLVMContext &Context, Module &M) {
+  DIBuilder DIB(M);
+  DIFile *File = DIB.createFile("-", ".");
+  DIB.createCompileUnit(dwarf::DW_LANG_C99, File, "producer", false, "", 0);
+  DISubroutineType *MainType = DIB.createSubroutineType({});
+  DISubprogram *DIMain = DIB.createFunction(File, "main", "main", File, 1,
+                                            MainType, false, true, 1);
+  DILocation *Loc = DILocation::get(Context, 1, 1, DIMain, nullptr);
+  Function *Main = Function::Create(TypeBuilder<int(void), false>::get(Context),
+                                    GlobalValue::ExternalLinkage, "main", &M);
+  Main->setSubprogram(DIMain);
+  BasicBlock *Entry = BasicBlock::Create(Context, "entry", Main);
+  ReturnInst *Ret =
+      IRBuilder<>(Entry).CreateRet(ConstantInt::get(Context, APInt(32, 47)));
+  Ret->setDebugLoc(Loc);
+  DIB.finalize();
+
+  return Main;
+}
+
+TEST_F(MCJITTest, ProcessAllSections) {
+  Function *Main = insertMainWithDI(Context, *M);
+
+  createJIT(std::move(M));
+  TheJIT->setProcessAllSections(true);
+  TheJIT->finalizeObject();
+
+  uint64_t ptr = TheJIT->getFunctionAddress(Main->getName().str());
+  ASSERT_NE(0u, ptr) << "Unable to get pointer to main() from JIT";
+
+  int (*FuncPtr)() = (int (*)())ptr;
+  int returnCode = FuncPtr();
+  EXPECT_EQ(returnCode, 47);
+}
+
 } // end anonymous namespace


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33269.99260.patch
Type: text/x-patch
Size: 2012 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170517/051b7edf/attachment.bin>


More information about the llvm-commits mailing list