#include "llvm/IR/ValueHandle.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h"
#include "gtest/gtest.h"
#include <memory>
usingnamespacellvm;
namespace {
class ValueHandle : public testing::Test { … };
class ConcreteCallbackVH final : public CallbackVH { … };
TEST_F(ValueHandle, WeakVH_BasicOperation) { … }
TEST_F(ValueHandle, WeakTrackingVH_BasicOperation) { … }
TEST_F(ValueHandle, WeakTrackingVH_Comparisons) { … }
TEST_F(ValueHandle, WeakTrackingVH_FollowsRAUW) { … }
TEST_F(ValueHandle, WeakTrackingVH_NullOnDeletion) { … }
TEST_F(ValueHandle, AssertingVH_BasicOperation) { … }
TEST_F(ValueHandle, AssertingVH_Const) { … }
TEST_F(ValueHandle, AssertingVH_Comparisons) { … }
TEST_F(ValueHandle, AssertingVH_DoesNotFollowRAUW) { … }
#ifdef NDEBUG
TEST_F(ValueHandle, AssertingVH_ReducesToPointer) { … }
#elif LLVM_ENABLE_ABI_BREAKING_CHECKS
#ifdef GTEST_HAS_DEATH_TEST
TEST_F(ValueHandle, AssertingVH_Asserts) {
AssertingVH<Value> AVH(BitcastV.get());
EXPECT_DEATH({BitcastV.reset();},
"An asserting value handle still pointed to this value!");
AssertingVH<Value> Copy(AVH);
AVH = nullptr;
EXPECT_DEATH({BitcastV.reset();},
"An asserting value handle still pointed to this value!");
Copy = nullptr;
BitcastV.reset();
}
#endif
#endif
TEST_F(ValueHandle, CallbackVH_BasicOperation) { … }
TEST_F(ValueHandle, CallbackVH_Comparisons) { … }
TEST_F(ValueHandle, CallbackVH_CallbackOnDeletion) { … }
TEST_F(ValueHandle, CallbackVH_CallbackOnRAUW) { … }
TEST_F(ValueHandle, CallbackVH_DeletionCanRAUW) { … }
TEST_F(ValueHandle, DestroyingOtherVHOnSameValueDoesntBreakIteration) { … }
TEST_F(ValueHandle, AssertingVHCheckedLast) { … }
TEST_F(ValueHandle, PoisoningVH_BasicOperation) { … }
TEST_F(ValueHandle, PoisoningVH_Const) { … }
TEST_F(ValueHandle, PoisoningVH_Comparisons) { … }
TEST_F(ValueHandle, PoisoningVH_DoesNotFollowRAUW) { … }
TEST_F(ValueHandle, AssertingVH_DenseMap) { … }
TEST_F(ValueHandle, PoisoningVH_DenseMap) { … }
#ifdef NDEBUG
TEST_F(ValueHandle, PoisoningVH_ReducesToPointer) { … }
#else
TEST_F(ValueHandle, TrackingVH_Tracks) {
TrackingVH<Value> VH(BitcastV.get());
BitcastV->replaceAllUsesWith(ConstantV);
EXPECT_EQ(VH, ConstantV);
}
#ifdef GTEST_HAS_DEATH_TEST
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
TEST_F(ValueHandle, PoisoningVH_Asserts) {
PoisoningVH<Value> VH(BitcastV.get());
BitcastV.reset(new BitCastInst(ConstantV, Type::getInt32Ty(Context)));
EXPECT_DEATH((void)*VH, "Accessed a poisoned value handle!");
VH = BitcastV.get();
BitcastV->replaceAllUsesWith(ConstantV);
EXPECT_DEATH((void)*VH, "Accessed a poisoned value handle!");
}
#endif
TEST_F(ValueHandle, TrackingVH_Asserts) {
{
TrackingVH<Value> VH(BitcastV.get());
BitcastV.reset(new BitCastInst(ConstantV, Type::getInt32Ty(Context)));
EXPECT_DEATH((void)*VH,
"TrackingVH must be non-null and valid on dereference!");
}
{
TrackingVH<Instruction> VH(BitcastV.get());
BitcastV->replaceAllUsesWith(ConstantV);
EXPECT_DEATH((void)*VH,
"Tracked Value was replaced by one with an invalid type!");
}
}
#endif
#endif
}