Skip to content

Commit dd4106d

Browse files
committed
[NFC] Edit the comment in User::replaceUsesOfWith
1 parent c12394f commit dd4106d

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

llvm/lib/IR/User.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void User::replaceUsesOfWith(Value *From, Value *To) {
2929
// The side effects of this setOperand call include linking to
3030
// "To", adding "this" to the uses list of To, and
3131
// most importantly, removing "this" from the use list of "From".
32-
setOperand(i, To); // Fix it now...
32+
setOperand(i, To);
3333
}
3434
}
3535

llvm/unittests/IR/UserTest.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,38 @@ TEST(UserTest, ValueOpIteration) {
117117
EXPECT_EQ(IP->value_op_end(), (CI - 2) + 8);
118118
}
119119

120+
TEST(UserTest, replaceUseOfWith) {
121+
LLVMContext C;
122+
123+
const char *ModuleString = "define void @f(i32 %x) {\n"
124+
"entry:\n"
125+
" %v0 = add i32 1, 1\n"
126+
" %v1 = add i32 %x, 2\n"
127+
" ret void\n"
128+
"}\n";
129+
SMDiagnostic Err;
130+
std::unique_ptr<Module> M = parseAssemblyString(ModuleString, Err, C);
131+
Function *F = M->getFunction("f");
132+
EXPECT_TRUE(F);
133+
EXPECT_TRUE(F->arg_begin() != F->arg_end());
134+
BasicBlock& entryBB = F->front();
135+
Instruction& I0 = *(entryBB.begin());
136+
Instruction& I1 = *(++(entryBB.begin()));
137+
138+
Argument &X = *F->arg_begin();
139+
EXPECT_EQ("x", X.getName());
140+
EXPECT_NE(X.user_begin() ,X.user_end());
141+
EXPECT_EQ(I0.user_begin() ,I0.user_end());
142+
143+
144+
auto XUser = find(X.users(), &(I1));
145+
EXPECT_NE(XUser, X.user_end());
146+
147+
XUser->replaceUsesOfWith(&X, &I0);
148+
EXPECT_EQ(X.user_begin() ,X.user_end());
149+
EXPECT_NE(I0.user_begin() ,I0.user_end());
150+
}
151+
120152
TEST(UserTest, PersonalityUser) {
121153
LLVMContext Context;
122154
Module M("", Context);

0 commit comments

Comments
 (0)