summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/IR/ValueHandleTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/unittests/IR/ValueHandleTest.cpp')
-rw-r--r--llvm/unittests/IR/ValueHandleTest.cpp44
1 files changed, 23 insertions, 21 deletions
diff --git a/llvm/unittests/IR/ValueHandleTest.cpp b/llvm/unittests/IR/ValueHandleTest.cpp
index e1d598bbc58..59cd9d7ba37 100644
--- a/llvm/unittests/IR/ValueHandleTest.cpp
+++ b/llvm/unittests/IR/ValueHandleTest.cpp
@@ -20,13 +20,13 @@ namespace {
class ValueHandle : public testing::Test {
protected:
+ LLVMContext Context;
Constant *ConstantV;
std::unique_ptr<BitCastInst> BitcastV;
- ValueHandle() :
- ConstantV(ConstantInt::get(Type::getInt32Ty(getGlobalContext()), 0)),
- BitcastV(new BitCastInst(ConstantV, Type::getInt32Ty(getGlobalContext()))) {
- }
+ ValueHandle()
+ : ConstantV(ConstantInt::get(Type::getInt32Ty(Context), 0)),
+ BitcastV(new BitCastInst(ConstantV, Type::getInt32Ty(Context))) {}
};
class ConcreteCallbackVH final : public CallbackVH {
@@ -42,8 +42,8 @@ TEST_F(ValueHandle, WeakVH_BasicOperation) {
// Make sure I can call a method on the underlying Value. It
// doesn't matter which method.
- EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), WVH->getType());
- EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), (*WVH).getType());
+ EXPECT_EQ(Type::getInt32Ty(Context), WVH->getType());
+ EXPECT_EQ(Type::getInt32Ty(Context), (*WVH).getType());
}
TEST_F(ValueHandle, WeakVH_Comparisons) {
@@ -197,8 +197,8 @@ TEST_F(ValueHandle, CallbackVH_BasicOperation) {
// Make sure I can call a method on the underlying Value. It
// doesn't matter which method.
- EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), CVH->getType());
- EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), (*CVH).getType());
+ EXPECT_EQ(Type::getInt32Ty(Context), CVH->getType());
+ EXPECT_EQ(Type::getInt32Ty(Context), (*CVH).getType());
}
TEST_F(ValueHandle, CallbackVH_Comparisons) {
@@ -297,15 +297,17 @@ TEST_F(ValueHandle, CallbackVH_DeletionCanRAUW) {
Value *AURWArgument;
LLVMContext *Context;
- RecoveringVH() : DeletedCalls(0), AURWArgument(nullptr),
- Context(&getGlobalContext()) {}
- RecoveringVH(Value *V)
- : CallbackVH(V), DeletedCalls(0), AURWArgument(nullptr),
- Context(&getGlobalContext()) {}
+ RecoveringVH(LLVMContext &TheContext)
+ : DeletedCalls(0), AURWArgument(nullptr), Context(&TheContext) {}
+
+ RecoveringVH(LLVMContext &TheContext, Value *V)
+ : CallbackVH(V), DeletedCalls(0), AURWArgument(nullptr),
+ Context(&TheContext) {}
private:
void deleted() override {
- getValPtr()->replaceAllUsesWith(Constant::getNullValue(Type::getInt32Ty(getGlobalContext())));
+ getValPtr()->replaceAllUsesWith(
+ Constant::getNullValue(Type::getInt32Ty(*Context)));
setValPtr(nullptr);
}
void allUsesReplacedWith(Value *new_value) override {
@@ -318,15 +320,15 @@ TEST_F(ValueHandle, CallbackVH_DeletionCanRAUW) {
// Normally, if a value has uses, deleting it will crash. However, we can use
// a CallbackVH to remove the uses before the check for no uses.
- RecoveringVH RVH;
- RVH = BitcastV.get();
- std::unique_ptr<BinaryOperator> BitcastUser(
- BinaryOperator::CreateAdd(RVH,
- Constant::getNullValue(Type::getInt32Ty(getGlobalContext()))));
+ RecoveringVH RVH(Context);
+ RVH = RecoveringVH(Context, BitcastV.get());
+ std::unique_ptr<BinaryOperator> BitcastUser(BinaryOperator::CreateAdd(
+ RVH, Constant::getNullValue(Type::getInt32Ty(Context))));
EXPECT_EQ(BitcastV.get(), BitcastUser->getOperand(0));
BitcastV.reset(); // Would crash without the ValueHandler.
- EXPECT_EQ(Constant::getNullValue(Type::getInt32Ty(getGlobalContext())), RVH.AURWArgument);
- EXPECT_EQ(Constant::getNullValue(Type::getInt32Ty(getGlobalContext())),
+ EXPECT_EQ(Constant::getNullValue(Type::getInt32Ty(Context)),
+ RVH.AURWArgument);
+ EXPECT_EQ(Constant::getNullValue(Type::getInt32Ty(Context)),
BitcastUser->getOperand(0));
}
OpenPOWER on IntegriCloud