summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorRoman Divacky <rdivacky@FreeBSD.org>2009-11-04 14:58:56 +0000
committerRoman Divacky <rdivacky@FreeBSD.org>2009-11-04 14:58:56 +0000
commit36bf506ad3c99a309ca8bd73bd03563d8d068ac0 (patch)
treeb4dc751bcee540346911aa4115729eff2f991657 /unittests
parentf9666f9b3a3d26810deae8cd54feb6e47ecee61a (diff)
Diffstat (limited to 'unittests')
-rw-r--r--unittests/ADT/StringMapTest.cpp2
-rw-r--r--unittests/ADT/ValueMapTest.cpp8
-rw-r--r--unittests/ExecutionEngine/JIT/JITEventListenerTest.cpp11
-rw-r--r--unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp1
-rw-r--r--unittests/ExecutionEngine/JIT/JITTest.cpp198
-rw-r--r--unittests/ExecutionEngine/JIT/Makefile2
-rw-r--r--unittests/Makefile.unittest2
-rw-r--r--unittests/Support/ValueHandleTest.cpp1
-rw-r--r--unittests/Transforms/Utils/Cloning.cpp57
-rw-r--r--unittests/VMCore/MetadataTest.cpp1
10 files changed, 234 insertions, 49 deletions
diff --git a/unittests/ADT/StringMapTest.cpp b/unittests/ADT/StringMapTest.cpp
index 8ee166b5e28d..3dcdc39b904d 100644
--- a/unittests/ADT/StringMapTest.cpp
+++ b/unittests/ADT/StringMapTest.cpp
@@ -9,7 +9,7 @@
#include "gtest/gtest.h"
#include "llvm/ADT/StringMap.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
using namespace llvm;
namespace {
diff --git a/unittests/ADT/ValueMapTest.cpp b/unittests/ADT/ValueMapTest.cpp
index 9de340c3f355..915965753045 100644
--- a/unittests/ADT/ValueMapTest.cpp
+++ b/unittests/ADT/ValueMapTest.cpp
@@ -8,8 +8,8 @@
//===----------------------------------------------------------------------===//
#include "llvm/ADT/ValueMap.h"
-
#include "llvm/Instructions.h"
+#include "llvm/LLVMContext.h"
#include "llvm/ADT/OwningPtr.h"
#include "gtest/gtest.h"
@@ -187,7 +187,7 @@ struct LockMutex : ValueMapConfig<KeyT> {
*Data.CalledRAUW = true;
EXPECT_FALSE(Data.M->tryacquire()) << "Mutex should already be locked.";
}
- static void onDeleted(const ExtraData &Data, KeyT Old) {
+ static void onDelete(const ExtraData &Data, KeyT Old) {
*Data.CalledDeleted = true;
EXPECT_FALSE(Data.M->tryacquire()) << "Mutex should already be locked.";
}
@@ -238,7 +238,7 @@ struct CountOps : ValueMapConfig<KeyT> {
static void onRAUW(const ExtraData &Data, KeyT Old, KeyT New) {
++*Data.RAUWs;
}
- static void onDeleted(const ExtraData &Data, KeyT Old) {
+ static void onDelete(const ExtraData &Data, KeyT Old) {
++*Data.Deletions;
}
};
@@ -270,7 +270,7 @@ struct ModifyingConfig : ValueMapConfig<KeyT> {
static void onRAUW(ExtraData Map, KeyT Old, KeyT New) {
(*Map)->erase(Old);
}
- static void onDeleted(ExtraData Map, KeyT Old) {
+ static void onDelete(ExtraData Map, KeyT Old) {
(*Map)->erase(Old);
}
};
diff --git a/unittests/ExecutionEngine/JIT/JITEventListenerTest.cpp b/unittests/ExecutionEngine/JIT/JITEventListenerTest.cpp
index 87e3280cf986..dda86fbe399f 100644
--- a/unittests/ExecutionEngine/JIT/JITEventListenerTest.cpp
+++ b/unittests/ExecutionEngine/JIT/JITEventListenerTest.cpp
@@ -37,7 +37,6 @@ struct FunctionEmittedEvent {
};
struct FunctionFreedEvent {
unsigned Index;
- const Function *F;
void *Code;
};
@@ -56,8 +55,8 @@ struct RecordingJITEventListener : public JITEventListener {
EmittedEvents.push_back(Event);
}
- virtual void NotifyFreeingMachineCode(const Function &F, void *OldPtr) {
- FunctionFreedEvent Event = {NextIndex++, &F, OldPtr};
+ virtual void NotifyFreeingMachineCode(void *OldPtr) {
+ FunctionFreedEvent Event = {NextIndex++, OldPtr};
FreedEvents.push_back(Event);
}
};
@@ -116,11 +115,9 @@ TEST_F(JITEventListenerTest, Simple) {
<< " contain some bytes.";
EXPECT_EQ(2U, Listener.FreedEvents[0].Index);
- EXPECT_EQ(F1, Listener.FreedEvents[0].F);
EXPECT_EQ(F1_addr, Listener.FreedEvents[0].Code);
EXPECT_EQ(3U, Listener.FreedEvents[1].Index);
- EXPECT_EQ(F2, Listener.FreedEvents[1].F);
EXPECT_EQ(F2_addr, Listener.FreedEvents[1].Code);
F1->eraseFromParent();
@@ -164,7 +161,6 @@ TEST_F(JITEventListenerTest, MultipleListenersDontInterfere) {
<< " contain some bytes.";
EXPECT_EQ(1U, Listener1.FreedEvents[0].Index);
- EXPECT_EQ(F2, Listener1.FreedEvents[0].F);
EXPECT_EQ(F2_addr, Listener1.FreedEvents[0].Code);
// Listener 2.
@@ -186,7 +182,6 @@ TEST_F(JITEventListenerTest, MultipleListenersDontInterfere) {
<< " contain some bytes.";
EXPECT_EQ(2U, Listener2.FreedEvents[0].Index);
- EXPECT_EQ(F2, Listener2.FreedEvents[0].F);
EXPECT_EQ(F2_addr, Listener2.FreedEvents[0].Code);
// Listener 3.
@@ -201,7 +196,6 @@ TEST_F(JITEventListenerTest, MultipleListenersDontInterfere) {
<< " contain some bytes.";
EXPECT_EQ(1U, Listener3.FreedEvents[0].Index);
- EXPECT_EQ(F2, Listener3.FreedEvents[0].F);
EXPECT_EQ(F2_addr, Listener3.FreedEvents[0].Code);
F1->eraseFromParent();
@@ -228,7 +222,6 @@ TEST_F(JITEventListenerTest, MatchesMachineCodeInfo) {
EXPECT_EQ(MCI.size(), Listener.EmittedEvents[0].Size);
EXPECT_EQ(1U, Listener.FreedEvents[0].Index);
- EXPECT_EQ(F, Listener.FreedEvents[0].F);
EXPECT_EQ(F_addr, Listener.FreedEvents[0].Code);
}
diff --git a/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp b/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp
index f0c491fba5b3..aa0c41d3ed2a 100644
--- a/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp
+++ b/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp
@@ -13,6 +13,7 @@
#include "llvm/DerivedTypes.h"
#include "llvm/Function.h"
#include "llvm/GlobalValue.h"
+#include "llvm/LLVMContext.h"
using namespace llvm;
diff --git a/unittests/ExecutionEngine/JIT/JITTest.cpp b/unittests/ExecutionEngine/JIT/JITTest.cpp
index 8f9b65ab0bad..e0568ad2dcd0 100644
--- a/unittests/ExecutionEngine/JIT/JITTest.cpp
+++ b/unittests/ExecutionEngine/JIT/JITTest.cpp
@@ -9,6 +9,8 @@
#include "gtest/gtest.h"
#include "llvm/ADT/OwningPtr.h"
+#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/Assembly/Parser.h"
#include "llvm/BasicBlock.h"
#include "llvm/Constant.h"
#include "llvm/Constants.h"
@@ -22,10 +24,13 @@
#include "llvm/Module.h"
#include "llvm/ModuleProvider.h"
#include "llvm/Support/IRBuilder.h"
+#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/TypeBuilder.h"
#include "llvm/Target/TargetSelect.h"
#include "llvm/Type.h"
+#include <vector>
+
using namespace llvm;
namespace {
@@ -45,18 +50,158 @@ Function *makeReturnGlobal(std::string Name, GlobalVariable *G, Module *M) {
return F;
}
+std::string DumpFunction(const Function *F) {
+ std::string Result;
+ raw_string_ostream(Result) << "" << *F;
+ return Result;
+}
+
+class RecordingJITMemoryManager : public JITMemoryManager {
+ const OwningPtr<JITMemoryManager> Base;
+public:
+ RecordingJITMemoryManager()
+ : Base(JITMemoryManager::CreateDefaultMemManager()) {
+ }
+
+ virtual void setMemoryWritable() { Base->setMemoryWritable(); }
+ virtual void setMemoryExecutable() { Base->setMemoryExecutable(); }
+ virtual void setPoisonMemory(bool poison) { Base->setPoisonMemory(poison); }
+ virtual void AllocateGOT() { Base->AllocateGOT(); }
+ virtual uint8_t *getGOTBase() const { return Base->getGOTBase(); }
+ virtual void SetDlsymTable(void *ptr) { Base->SetDlsymTable(ptr); }
+ virtual void *getDlsymTable() const { return Base->getDlsymTable(); }
+ struct StartFunctionBodyCall {
+ StartFunctionBodyCall(uint8_t *Result, const Function *F,
+ uintptr_t ActualSize, uintptr_t ActualSizeResult)
+ : Result(Result), F(F), F_dump(DumpFunction(F)),
+ ActualSize(ActualSize), ActualSizeResult(ActualSizeResult) {}
+ uint8_t *Result;
+ const Function *F;
+ std::string F_dump;
+ uintptr_t ActualSize;
+ uintptr_t ActualSizeResult;
+ };
+ std::vector<StartFunctionBodyCall> startFunctionBodyCalls;
+ virtual uint8_t *startFunctionBody(const Function *F,
+ uintptr_t &ActualSize) {
+ uintptr_t InitialActualSize = ActualSize;
+ uint8_t *Result = Base->startFunctionBody(F, ActualSize);
+ startFunctionBodyCalls.push_back(
+ StartFunctionBodyCall(Result, F, InitialActualSize, ActualSize));
+ return Result;
+ }
+ virtual uint8_t *allocateStub(const GlobalValue* F, unsigned StubSize,
+ unsigned Alignment) {
+ return Base->allocateStub(F, StubSize, Alignment);
+ }
+ struct EndFunctionBodyCall {
+ EndFunctionBodyCall(const Function *F, uint8_t *FunctionStart,
+ uint8_t *FunctionEnd)
+ : F(F), F_dump(DumpFunction(F)),
+ FunctionStart(FunctionStart), FunctionEnd(FunctionEnd) {}
+ const Function *F;
+ std::string F_dump;
+ uint8_t *FunctionStart;
+ uint8_t *FunctionEnd;
+ };
+ std::vector<EndFunctionBodyCall> endFunctionBodyCalls;
+ virtual void endFunctionBody(const Function *F, uint8_t *FunctionStart,
+ uint8_t *FunctionEnd) {
+ endFunctionBodyCalls.push_back(
+ EndFunctionBodyCall(F, FunctionStart, FunctionEnd));
+ Base->endFunctionBody(F, FunctionStart, FunctionEnd);
+ }
+ virtual uint8_t *allocateSpace(intptr_t Size, unsigned Alignment) {
+ return Base->allocateSpace(Size, Alignment);
+ }
+ virtual uint8_t *allocateGlobal(uintptr_t Size, unsigned Alignment) {
+ return Base->allocateGlobal(Size, Alignment);
+ }
+ struct DeallocateFunctionBodyCall {
+ DeallocateFunctionBodyCall(const void *Body) : Body(Body) {}
+ const void *Body;
+ };
+ std::vector<DeallocateFunctionBodyCall> deallocateFunctionBodyCalls;
+ virtual void deallocateFunctionBody(void *Body) {
+ deallocateFunctionBodyCalls.push_back(DeallocateFunctionBodyCall(Body));
+ Base->deallocateFunctionBody(Body);
+ }
+ struct DeallocateExceptionTableCall {
+ DeallocateExceptionTableCall(const void *ET) : ET(ET) {}
+ const void *ET;
+ };
+ std::vector<DeallocateExceptionTableCall> deallocateExceptionTableCalls;
+ virtual void deallocateExceptionTable(void *ET) {
+ deallocateExceptionTableCalls.push_back(DeallocateExceptionTableCall(ET));
+ Base->deallocateExceptionTable(ET);
+ }
+ struct StartExceptionTableCall {
+ StartExceptionTableCall(uint8_t *Result, const Function *F,
+ uintptr_t ActualSize, uintptr_t ActualSizeResult)
+ : Result(Result), F(F), F_dump(DumpFunction(F)),
+ ActualSize(ActualSize), ActualSizeResult(ActualSizeResult) {}
+ uint8_t *Result;
+ const Function *F;
+ std::string F_dump;
+ uintptr_t ActualSize;
+ uintptr_t ActualSizeResult;
+ };
+ std::vector<StartExceptionTableCall> startExceptionTableCalls;
+ virtual uint8_t* startExceptionTable(const Function* F,
+ uintptr_t &ActualSize) {
+ uintptr_t InitialActualSize = ActualSize;
+ uint8_t *Result = Base->startExceptionTable(F, ActualSize);
+ startExceptionTableCalls.push_back(
+ StartExceptionTableCall(Result, F, InitialActualSize, ActualSize));
+ return Result;
+ }
+ struct EndExceptionTableCall {
+ EndExceptionTableCall(const Function *F, uint8_t *TableStart,
+ uint8_t *TableEnd, uint8_t* FrameRegister)
+ : F(F), F_dump(DumpFunction(F)),
+ TableStart(TableStart), TableEnd(TableEnd),
+ FrameRegister(FrameRegister) {}
+ const Function *F;
+ std::string F_dump;
+ uint8_t *TableStart;
+ uint8_t *TableEnd;
+ uint8_t *FrameRegister;
+ };
+ std::vector<EndExceptionTableCall> endExceptionTableCalls;
+ virtual void endExceptionTable(const Function *F, uint8_t *TableStart,
+ uint8_t *TableEnd, uint8_t* FrameRegister) {
+ endExceptionTableCalls.push_back(
+ EndExceptionTableCall(F, TableStart, TableEnd, FrameRegister));
+ return Base->endExceptionTable(F, TableStart, TableEnd, FrameRegister);
+ }
+};
+
class JITTest : public testing::Test {
protected:
virtual void SetUp() {
M = new Module("<main>", Context);
+ MP = new ExistingModuleProvider(M);
+ RJMM = new RecordingJITMemoryManager;
std::string Error;
- TheJIT.reset(EngineBuilder(M).setEngineKind(EngineKind::JIT)
+ TheJIT.reset(EngineBuilder(MP).setEngineKind(EngineKind::JIT)
+ .setJITMemoryManager(RJMM)
.setErrorStr(&Error).create());
ASSERT_TRUE(TheJIT.get() != NULL) << Error;
}
+ void LoadAssembly(const char *assembly) {
+ SMDiagnostic Error;
+ bool success = NULL != ParseAssemblyString(assembly, M, Error, Context);
+ std::string errMsg;
+ raw_string_ostream os(errMsg);
+ Error.Print("", os);
+ ASSERT_TRUE(success) << os.str();
+ }
+
LLVMContext Context;
- Module *M; // Owned by ExecutionEngine.
+ Module *M; // Owned by MP.
+ ModuleProvider *MP; // Owned by ExecutionEngine.
+ RecordingJITMemoryManager *RJMM;
OwningPtr<ExecutionEngine> TheJIT;
};
@@ -159,7 +304,7 @@ TEST_F(JITTest, FarCallToKnownFunction) {
Builder.CreateRet(result);
TheJIT->EnableDlsymStubs(false);
- TheJIT->DisableLazyCompilation();
+ TheJIT->DisableLazyCompilation(true);
int (*TestFunctionPtr)() = reinterpret_cast<int(*)()>(
(intptr_t)TheJIT->getPointerToFunction(TestFunction));
// This used to crash in trying to call PlusOne().
@@ -169,7 +314,7 @@ TEST_F(JITTest, FarCallToKnownFunction) {
#if !defined(__arm__) && !defined(__powerpc__) && !defined(__ppc__)
// Test a function C which calls A and B which call each other.
TEST_F(JITTest, NonLazyCompilationStillNeedsStubs) {
- TheJIT->DisableLazyCompilation();
+ TheJIT->DisableLazyCompilation(true);
const FunctionType *Func1Ty =
cast<FunctionType>(TypeBuilder<void(void), false>::get(Context));
@@ -225,7 +370,7 @@ TEST_F(JITTest, NonLazyCompilationStillNeedsStubs) {
// Regression test for PR5162. This used to trigger an AssertingVH inside the
// JIT's Function to stub mapping.
TEST_F(JITTest, NonLazyLeaksNoStubs) {
- TheJIT->DisableLazyCompilation();
+ TheJIT->DisableLazyCompilation(true);
// Create two functions with a single basic block each.
const FunctionType *FuncTy =
@@ -264,6 +409,49 @@ TEST_F(JITTest, NonLazyLeaksNoStubs) {
}
#endif
+TEST_F(JITTest, ModuleDeletion) {
+ TheJIT->DisableLazyCompilation(false);
+ LoadAssembly("define void @main() { "
+ " call i32 @computeVal() "
+ " ret void "
+ "} "
+ " "
+ "define internal i32 @computeVal() { "
+ " ret i32 0 "
+ "} ");
+ Function *func = M->getFunction("main");
+ TheJIT->getPointerToFunction(func);
+ TheJIT->deleteModuleProvider(MP);
+
+ SmallPtrSet<const void*, 2> FunctionsDeallocated;
+ for (unsigned i = 0, e = RJMM->deallocateFunctionBodyCalls.size();
+ i != e; ++i) {
+ FunctionsDeallocated.insert(RJMM->deallocateFunctionBodyCalls[i].Body);
+ }
+ for (unsigned i = 0, e = RJMM->startFunctionBodyCalls.size(); i != e; ++i) {
+ EXPECT_TRUE(FunctionsDeallocated.count(
+ RJMM->startFunctionBodyCalls[i].Result))
+ << "Function leaked: \n" << RJMM->startFunctionBodyCalls[i].F_dump;
+ }
+ EXPECT_EQ(RJMM->startFunctionBodyCalls.size(),
+ RJMM->deallocateFunctionBodyCalls.size());
+
+ SmallPtrSet<const void*, 2> ExceptionTablesDeallocated;
+ for (unsigned i = 0, e = RJMM->deallocateExceptionTableCalls.size();
+ i != e; ++i) {
+ ExceptionTablesDeallocated.insert(
+ RJMM->deallocateExceptionTableCalls[i].ET);
+ }
+ for (unsigned i = 0, e = RJMM->startExceptionTableCalls.size(); i != e; ++i) {
+ EXPECT_TRUE(ExceptionTablesDeallocated.count(
+ RJMM->startExceptionTableCalls[i].Result))
+ << "Function's exception table leaked: \n"
+ << RJMM->startExceptionTableCalls[i].F_dump;
+ }
+ EXPECT_EQ(RJMM->startExceptionTableCalls.size(),
+ RJMM->deallocateExceptionTableCalls.size());
+}
+
// This code is copied from JITEventListenerTest, but it only runs once for all
// the tests in this directory. Everything seems fine, but that's strange
// behavior.
diff --git a/unittests/ExecutionEngine/JIT/Makefile b/unittests/ExecutionEngine/JIT/Makefile
index 0069c7687a01..048924ae26d4 100644
--- a/unittests/ExecutionEngine/JIT/Makefile
+++ b/unittests/ExecutionEngine/JIT/Makefile
@@ -9,7 +9,7 @@
LEVEL = ../../..
TESTNAME = JIT
-LINK_COMPONENTS := core support jit native
+LINK_COMPONENTS := asmparser core support jit native
include $(LEVEL)/Makefile.config
include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest
diff --git a/unittests/Makefile.unittest b/unittests/Makefile.unittest
index 76051e497c96..e4174355ed75 100644
--- a/unittests/Makefile.unittest
+++ b/unittests/Makefile.unittest
@@ -19,7 +19,7 @@ include $(LEVEL)/Makefile.common
LLVMUnitTestExe = $(BuildMode)/$(TESTNAME)Tests$(EXEEXT)
CPP.Flags += -I$(LLVM_SRC_ROOT)/utils/unittest/googletest/include/
-CPP.Flags += -Wno-variadic-macros
+CPP.Flags += $(NO_VARIADIC_MACROS)
TESTLIBS = -lGoogleTest -lUnitTestMain
$(LLVMUnitTestExe): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
diff --git a/unittests/Support/ValueHandleTest.cpp b/unittests/Support/ValueHandleTest.cpp
index c89a7af6fefe..6a6528fbddfb 100644
--- a/unittests/Support/ValueHandleTest.cpp
+++ b/unittests/Support/ValueHandleTest.cpp
@@ -11,6 +11,7 @@
#include "llvm/Constants.h"
#include "llvm/Instructions.h"
+#include "llvm/LLVMContext.h"
#include "llvm/ADT/OwningPtr.h"
#include "gtest/gtest.h"
diff --git a/unittests/Transforms/Utils/Cloning.cpp b/unittests/Transforms/Utils/Cloning.cpp
index b14114ab6912..17047e7ca15a 100644
--- a/unittests/Transforms/Utils/Cloning.cpp
+++ b/unittests/Transforms/Utils/Cloning.cpp
@@ -10,6 +10,7 @@
#include "gtest/gtest.h"
#include "llvm/Argument.h"
#include "llvm/Instructions.h"
+#include "llvm/LLVMContext.h"
using namespace llvm;
@@ -21,45 +22,45 @@ TEST(CloneInstruction, OverflowBits) {
BinaryOperator *Sub = BinaryOperator::Create(Instruction::Sub, V, V);
BinaryOperator *Mul = BinaryOperator::Create(Instruction::Mul, V, V);
- EXPECT_FALSE(Add->clone()->hasNoUnsignedWrap());
- EXPECT_FALSE(Add->clone()->hasNoSignedWrap());
- EXPECT_FALSE(Sub->clone()->hasNoUnsignedWrap());
- EXPECT_FALSE(Sub->clone()->hasNoSignedWrap());
- EXPECT_FALSE(Mul->clone()->hasNoUnsignedWrap());
- EXPECT_FALSE(Mul->clone()->hasNoSignedWrap());
+ EXPECT_FALSE(cast<BinaryOperator>(Add->clone())->hasNoUnsignedWrap());
+ EXPECT_FALSE(cast<BinaryOperator>(Add->clone())->hasNoSignedWrap());
+ EXPECT_FALSE(cast<BinaryOperator>(Sub->clone())->hasNoUnsignedWrap());
+ EXPECT_FALSE(cast<BinaryOperator>(Sub->clone())->hasNoSignedWrap());
+ EXPECT_FALSE(cast<BinaryOperator>(Mul->clone())->hasNoUnsignedWrap());
+ EXPECT_FALSE(cast<BinaryOperator>(Mul->clone())->hasNoSignedWrap());
Add->setHasNoUnsignedWrap();
Sub->setHasNoUnsignedWrap();
Mul->setHasNoUnsignedWrap();
- EXPECT_TRUE(Add->clone()->hasNoUnsignedWrap());
- EXPECT_FALSE(Add->clone()->hasNoSignedWrap());
- EXPECT_TRUE(Sub->clone()->hasNoUnsignedWrap());
- EXPECT_FALSE(Sub->clone()->hasNoSignedWrap());
- EXPECT_TRUE(Mul->clone()->hasNoUnsignedWrap());
- EXPECT_FALSE(Mul->clone()->hasNoSignedWrap());
+ EXPECT_TRUE(cast<BinaryOperator>(Add->clone())->hasNoUnsignedWrap());
+ EXPECT_FALSE(cast<BinaryOperator>(Add->clone())->hasNoSignedWrap());
+ EXPECT_TRUE(cast<BinaryOperator>(Sub->clone())->hasNoUnsignedWrap());
+ EXPECT_FALSE(cast<BinaryOperator>(Sub->clone())->hasNoSignedWrap());
+ EXPECT_TRUE(cast<BinaryOperator>(Mul->clone())->hasNoUnsignedWrap());
+ EXPECT_FALSE(cast<BinaryOperator>(Mul->clone())->hasNoSignedWrap());
Add->setHasNoSignedWrap();
Sub->setHasNoSignedWrap();
Mul->setHasNoSignedWrap();
- EXPECT_TRUE(Add->clone()->hasNoUnsignedWrap());
- EXPECT_TRUE(Add->clone()->hasNoSignedWrap());
- EXPECT_TRUE(Sub->clone()->hasNoUnsignedWrap());
- EXPECT_TRUE(Sub->clone()->hasNoSignedWrap());
- EXPECT_TRUE(Mul->clone()->hasNoUnsignedWrap());
- EXPECT_TRUE(Mul->clone()->hasNoSignedWrap());
+ EXPECT_TRUE(cast<BinaryOperator>(Add->clone())->hasNoUnsignedWrap());
+ EXPECT_TRUE(cast<BinaryOperator>(Add->clone())->hasNoSignedWrap());
+ EXPECT_TRUE(cast<BinaryOperator>(Sub->clone())->hasNoUnsignedWrap());
+ EXPECT_TRUE(cast<BinaryOperator>(Sub->clone())->hasNoSignedWrap());
+ EXPECT_TRUE(cast<BinaryOperator>(Mul->clone())->hasNoUnsignedWrap());
+ EXPECT_TRUE(cast<BinaryOperator>(Mul->clone())->hasNoSignedWrap());
Add->setHasNoUnsignedWrap(false);
Sub->setHasNoUnsignedWrap(false);
Mul->setHasNoUnsignedWrap(false);
- EXPECT_FALSE(Add->clone()->hasNoUnsignedWrap());
- EXPECT_TRUE(Add->clone()->hasNoSignedWrap());
- EXPECT_FALSE(Sub->clone()->hasNoUnsignedWrap());
- EXPECT_TRUE(Sub->clone()->hasNoSignedWrap());
- EXPECT_FALSE(Mul->clone()->hasNoUnsignedWrap());
- EXPECT_TRUE(Mul->clone()->hasNoSignedWrap());
+ EXPECT_FALSE(cast<BinaryOperator>(Add->clone())->hasNoUnsignedWrap());
+ EXPECT_TRUE(cast<BinaryOperator>(Add->clone())->hasNoSignedWrap());
+ EXPECT_FALSE(cast<BinaryOperator>(Sub->clone())->hasNoUnsignedWrap());
+ EXPECT_TRUE(cast<BinaryOperator>(Sub->clone())->hasNoSignedWrap());
+ EXPECT_FALSE(cast<BinaryOperator>(Mul->clone())->hasNoUnsignedWrap());
+ EXPECT_TRUE(cast<BinaryOperator>(Mul->clone())->hasNoSignedWrap());
}
TEST(CloneInstruction, Inbounds) {
@@ -69,10 +70,10 @@ TEST(CloneInstruction, Inbounds) {
std::vector<Value *> ops;
ops.push_back(Z);
GetElementPtrInst *GEP = GetElementPtrInst::Create(V, ops.begin(), ops.end());
- EXPECT_FALSE(GEP->clone()->isInBounds());
+ EXPECT_FALSE(cast<GetElementPtrInst>(GEP->clone())->isInBounds());
GEP->setIsInBounds();
- EXPECT_TRUE(GEP->clone()->isInBounds());
+ EXPECT_TRUE(cast<GetElementPtrInst>(GEP->clone())->isInBounds());
}
TEST(CloneInstruction, Exact) {
@@ -80,8 +81,8 @@ TEST(CloneInstruction, Exact) {
Value *V = new Argument(Type::getInt32Ty(context));
BinaryOperator *SDiv = BinaryOperator::Create(Instruction::SDiv, V, V);
- EXPECT_FALSE(SDiv->clone()->isExact());
+ EXPECT_FALSE(cast<BinaryOperator>(SDiv->clone())->isExact());
SDiv->setIsExact(true);
- EXPECT_TRUE(SDiv->clone()->isExact());
+ EXPECT_TRUE(cast<BinaryOperator>(SDiv->clone())->isExact());
}
diff --git a/unittests/VMCore/MetadataTest.cpp b/unittests/VMCore/MetadataTest.cpp
index b92b068e259c..4bd777b8e820 100644
--- a/unittests/VMCore/MetadataTest.cpp
+++ b/unittests/VMCore/MetadataTest.cpp
@@ -10,6 +10,7 @@
#include "gtest/gtest.h"
#include "llvm/Constants.h"
#include "llvm/Instructions.h"
+#include "llvm/LLVMContext.h"
#include "llvm/Metadata.h"
#include "llvm/Module.h"
#include "llvm/Type.h"