@@ -136,6 +136,48 @@ define void @foo(ptr %ptr) {
136136 EXPECT_FALSE (sandboxir::Utils::atLowerAddress (L3, V3L3, SE, DL));
137137}
138138
139+ TEST_F (UtilsTest, GetExpected) {
140+ parseIR (C, R"IR(
141+ define float @foo(float %v, ptr %ptr) {
142+ %add = fadd float %v, %v
143+ store float %v, ptr %ptr
144+ ret float %v
145+ }
146+ define void @bar(float %v, ptr %ptr) {
147+ ret void
148+ }
149+ )IR" );
150+ llvm::Function &Foo = *M->getFunction (" foo" );
151+ sandboxir::Context Ctx (C);
152+
153+ Ctx.createFunction (&Foo);
154+ auto *FooBB = cast<sandboxir::BasicBlock>(Ctx.getValue (&*Foo.begin ()));
155+ auto FooIt = FooBB->begin ();
156+ auto Add = cast<sandboxir::Instruction>(&*FooIt++);
157+ auto *S0 = cast<sandboxir::Instruction>(&*FooIt++);
158+ auto *RetF = cast<sandboxir::Instruction>(&*FooIt++);
159+ // getExpectedValue
160+ EXPECT_EQ (sandboxir::Utils::getExpectedValue (Add), Add);
161+ EXPECT_EQ (sandboxir::Utils::getExpectedValue (S0),
162+ cast<sandboxir::StoreInst>(S0)->getValueOperand ());
163+ EXPECT_EQ (sandboxir::Utils::getExpectedValue (RetF),
164+ cast<sandboxir::ReturnInst>(RetF)->getReturnValue ());
165+ // getExpectedType
166+ EXPECT_EQ (sandboxir::Utils::getExpectedType (Add), Add->getType ());
167+ EXPECT_EQ (sandboxir::Utils::getExpectedType (S0),
168+ cast<sandboxir::StoreInst>(S0)->getValueOperand ()->getType ());
169+ EXPECT_EQ (sandboxir::Utils::getExpectedType (RetF),
170+ cast<sandboxir::ReturnInst>(RetF)->getReturnValue ()->getType ());
171+
172+ // getExpectedValue for void returns
173+ llvm::Function &Bar = *M->getFunction (" bar" );
174+ Ctx.createFunction (&Bar);
175+ auto *BarBB = cast<sandboxir::BasicBlock>(Ctx.getValue (&*Bar.begin ()));
176+ auto BarIt = BarBB->begin ();
177+ auto *RetV = cast<sandboxir::Instruction>(&*BarIt++);
178+ EXPECT_EQ (sandboxir::Utils::getExpectedValue (RetV), nullptr );
179+ }
180+
139181TEST_F (UtilsTest, GetNumBits) {
140182 parseIR (C, R"IR(
141183define void @foo(float %arg0, double %arg1, i8 %arg2, i64 %arg3, ptr %arg4) {
0 commit comments