@@ -117,6 +117,38 @@ TEST(UserTest, ValueOpIteration) {
117
117
EXPECT_EQ (IP->value_op_end (), (CI - 2 ) + 8 );
118
118
}
119
119
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
+
120
152
TEST (UserTest, PersonalityUser) {
121
153
LLVMContext Context;
122
154
Module M (" " , Context);
0 commit comments