summaryrefslogtreecommitdiffstats
path: root/llvm/unittests
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2012-01-02 07:49:53 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2012-01-02 07:49:53 +0000
commitb79934657c4d522193c04775447a1b72a63e9c00 (patch)
tree7ea2e7985916ab2db4eebd7521daf99c066723ae /llvm/unittests
parenteeb9d9fef6df03f4f1bd9db87a4cbdb2784efbf2 (diff)
downloadbcm5719-llvm-b79934657c4d522193c04775447a1b72a63e9c00.tar.gz
bcm5719-llvm-b79934657c4d522193c04775447a1b72a63e9c00.zip
Materialize functions whose basic blocks are used by global variables. Fixes
PR11677. llvm-svn: 147425
Diffstat (limited to 'llvm/unittests')
-rw-r--r--llvm/unittests/CMakeLists.txt1
-rw-r--r--llvm/unittests/VMCore/pr11677.cpp64
2 files changed, 65 insertions, 0 deletions
diff --git a/llvm/unittests/CMakeLists.txt b/llvm/unittests/CMakeLists.txt
index 2eff1642c41..3cd7f2f051d 100644
--- a/llvm/unittests/CMakeLists.txt
+++ b/llvm/unittests/CMakeLists.txt
@@ -112,6 +112,7 @@ set(VMCoreSources
VMCore/PassManagerTest.cpp
VMCore/ValueMapTest.cpp
VMCore/VerifierTest.cpp
+ VMCore/pr11677.cpp
)
# MSVC9 and 8 cannot compile ValueMapTest.cpp due to their bug.
diff --git a/llvm/unittests/VMCore/pr11677.cpp b/llvm/unittests/VMCore/pr11677.cpp
new file mode 100644
index 00000000000..362eec77630
--- /dev/null
+++ b/llvm/unittests/VMCore/pr11677.cpp
@@ -0,0 +1,64 @@
+//===- llvm/unittest/VMCore/pr11677.cpp - Test for blockaddr --------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Analysis/Verifier.h"
+#include "llvm/Bitcode/BitstreamWriter.h"
+#include "llvm/Bitcode/ReaderWriter.h"
+#include "llvm/Constants.h"
+#include "llvm/Instructions.h"
+#include "llvm/LLVMContext.h"
+#include "llvm/Module.h"
+#include "llvm/PassManager.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "gtest/gtest.h"
+
+namespace llvm {
+namespace {
+
+static Module *makeLLVMModule() {
+ Module* Mod = new Module("test-mem", getGlobalContext());
+
+ FunctionType* FuncTy =
+ FunctionType::get(Type::getVoidTy(Mod->getContext()), false);
+ Function* Func = Function::Create(FuncTy,GlobalValue::ExternalLinkage,
+ "func", Mod);
+
+ BasicBlock* Entry = BasicBlock::Create(Mod->getContext(), "entry", Func);
+ new UnreachableInst(Mod->getContext(), Entry);
+
+ BasicBlock* BB = BasicBlock::Create(Mod->getContext(), "bb", Func);
+ new UnreachableInst(Mod->getContext(), BB);
+
+ PointerType* Int8Ptr = Type::getInt8PtrTy(Mod->getContext());
+ new GlobalVariable(*Mod, Int8Ptr, /*isConstant=*/true,
+ GlobalValue::ExternalLinkage,
+ BlockAddress::get(BB), "table");
+
+ return Mod;
+}
+
+static void writeModuleToBuffer(std::vector<unsigned char> &Buffer) {
+ Module *Mod = makeLLVMModule();
+ BitstreamWriter Stream(Buffer);
+ WriteBitcodeToStream(Mod, Stream);
+}
+
+TEST(PR11677, BlockAddr) {
+ std::vector<unsigned char> Mem;
+ writeModuleToBuffer(Mem);
+ StringRef Data((const char*)&Mem[0], Mem.size());
+ MemoryBuffer *Buffer = MemoryBuffer::getMemBuffer(Data, "test", false);
+ std::string errMsg;
+ Module *m = getLazyBitcodeModule(Buffer, getGlobalContext(), &errMsg);
+ PassManager passes;
+ passes.add(createVerifierPass());
+ passes.run(*m);
+}
+}
+}
OpenPOWER on IntegriCloud