Skip to content

Commit

Permalink
[NFC] Edit the comment in User::replaceUsesOfWith
Browse files Browse the repository at this point in the history
  • Loading branch information
ChuanqiXu9 committed Jul 29, 2020
1 parent c12394f commit dd4106d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion llvm/lib/IR/User.cpp
Expand Up @@ -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);
}
}

Expand Down
32 changes: 32 additions & 0 deletions llvm/unittests/IR/UserTest.cpp
Expand Up @@ -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);
Expand Down

0 comments on commit dd4106d

Please sign in to comment.