aboutsummaryrefslogtreecommitdiffstats
path: root/unittests/IR/ConstantsTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'unittests/IR/ConstantsTest.cpp')
-rw-r--r--unittests/IR/ConstantsTest.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/unittests/IR/ConstantsTest.cpp b/unittests/IR/ConstantsTest.cpp
index b3aa810..c11729c 100644
--- a/unittests/IR/ConstantsTest.cpp
+++ b/unittests/IR/ConstantsTest.cpp
@@ -254,6 +254,34 @@ TEST(ConstantsTest, AsInstructionsTest) {
P6STR ", i32 1");
}
+#ifdef GTEST_HAS_DEATH_TEST
+#ifndef NDEBUG
+TEST(ConstantsTest, ReplaceWithConstantTest) {
+ std::unique_ptr<Module> M(new Module("MyModule", getGlobalContext()));
+
+ Type *Int32Ty = Type::getInt32Ty(getGlobalContext());
+ Constant *One = ConstantInt::get(Int32Ty, 1);
+
+ Constant *Global =
+ M->getOrInsertGlobal("dummy", PointerType::getUnqual(Int32Ty));
+ Constant *GEP = ConstantExpr::getGetElementPtr(Global, One);
+ EXPECT_DEATH(Global->replaceAllUsesWith(GEP),
+ "this->replaceAllUsesWith\\(expr\\(this\\)\\) is NOT valid!");
+}
+
+TEST(ConstantsTest, ReplaceInAliasTest) {
+ std::unique_ptr<Module> M(new Module("MyModule", getGlobalContext()));
+
+ Type *Int32Ty = Type::getInt32Ty(getGlobalContext());
+ auto *Global = cast<GlobalObject>(M->getOrInsertGlobal("dummy", Int32Ty));
+ auto *GA = GlobalAlias::create(GlobalValue::ExternalLinkage, "alias", Global);
+ EXPECT_DEATH(Global->replaceAllUsesWith(GA),
+ "replaceAliasUseWith cannot form an alias cycle");
+}
+
+#endif
+#endif
+
#undef CHECK
} // end anonymous namespace