[llvm] dd4106d - [NFC] Edit the comment in User::replaceUsesOfWith
Chuanqi Xu via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 28 19:02:29 PDT 2020
Author: Chuanqi Xu
Date: 2020-07-29T10:02:04+08:00
New Revision: dd4106d22ef6ce51bfac666584b76dd43e98acf6
URL: https://github.com/llvm/llvm-project/commit/dd4106d22ef6ce51bfac666584b76dd43e98acf6
DIFF: https://github.com/llvm/llvm-project/commit/dd4106d22ef6ce51bfac666584b76dd43e98acf6.diff
LOG: [NFC] Edit the comment in User::replaceUsesOfWith
Added:
Modified:
llvm/lib/IR/User.cpp
llvm/unittests/IR/UserTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/IR/User.cpp b/llvm/lib/IR/User.cpp
index 7da592f40127..9105c6fbd230 100644
--- a/llvm/lib/IR/User.cpp
+++ b/llvm/lib/IR/User.cpp
@@ -29,7 +29,7 @@ void User::replaceUsesOfWith(Value *From, Value *To) {
// The side effects of this setOperand call include linking to
// "To", adding "this" to the uses list of To, and
// most importantly, removing "this" from the use list of "From".
- setOperand(i, To); // Fix it now...
+ setOperand(i, To);
}
}
diff --git a/llvm/unittests/IR/UserTest.cpp b/llvm/unittests/IR/UserTest.cpp
index e495735aec65..8fd435ecbc2b 100644
--- a/llvm/unittests/IR/UserTest.cpp
+++ b/llvm/unittests/IR/UserTest.cpp
@@ -117,6 +117,38 @@ TEST(UserTest, ValueOpIteration) {
EXPECT_EQ(IP->value_op_end(), (CI - 2) + 8);
}
+TEST(UserTest, replaceUseOfWith) {
+ LLVMContext C;
+
+ const char *ModuleString = "define void @f(i32 %x) {\n"
+ "entry:\n"
+ " %v0 = add i32 1, 1\n"
+ " %v1 = add i32 %x, 2\n"
+ " ret void\n"
+ "}\n";
+ SMDiagnostic Err;
+ std::unique_ptr<Module> M = parseAssemblyString(ModuleString, Err, C);
+ Function *F = M->getFunction("f");
+ EXPECT_TRUE(F);
+ EXPECT_TRUE(F->arg_begin() != F->arg_end());
+ BasicBlock& entryBB = F->front();
+ Instruction& I0 = *(entryBB.begin());
+ Instruction& I1 = *(++(entryBB.begin()));
+
+ Argument &X = *F->arg_begin();
+ EXPECT_EQ("x", X.getName());
+ EXPECT_NE(X.user_begin() ,X.user_end());
+ EXPECT_EQ(I0.user_begin() ,I0.user_end());
+
+
+ auto XUser = find(X.users(), &(I1));
+ EXPECT_NE(XUser, X.user_end());
+
+ XUser->replaceUsesOfWith(&X, &I0);
+ EXPECT_EQ(X.user_begin() ,X.user_end());
+ EXPECT_NE(I0.user_begin() ,I0.user_end());
+}
+
TEST(UserTest, PersonalityUser) {
LLVMContext Context;
Module M("", Context);
More information about the llvm-commits
mailing list