Skip to content

Commit 669166d

Browse files
committed
Retrieve types properly from missing cases in FindVarInFunction
1 parent 67c5fd0 commit 669166d

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

lib/BC/Util.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -218,22 +218,20 @@ FindVarInFunction(llvm::BasicBlock *block, std::string_view name,
218218
std::pair<llvm::Value *, llvm::Type *>
219219
FindVarInFunction(llvm::Function *function, std::string_view name_,
220220
bool allow_failure) {
221-
// TODO(alex): Figure out how to to get types for the two cases below.
222221
llvm::StringRef name(name_.data(), name_.size());
223222
if (!function->empty()) {
224223
for (auto &instr : function->getEntryBlock()) {
225224
if (instr.getName() == name) {
226-
return {&instr, nullptr};
225+
if (auto *alloca = llvm::dyn_cast<llvm::AllocaInst>(&instr)) {
226+
return {alloca, alloca->getAllocatedType()};
227+
}
228+
if (auto *gep = llvm::dyn_cast<llvm::GetElementPtrInst>(&instr)) {
229+
return {gep, gep->getResultElementType()};
230+
}
227231
}
228232
}
229233
}
230234

231-
for (auto &arg : function->args()) {
232-
if (arg.getName() == name) {
233-
return {&arg, nullptr};
234-
}
235-
}
236-
237235
auto module = function->getParent();
238236
if (auto var = module->getGlobalVariable(name)) {
239237
return {var, var->getValueType()};

0 commit comments

Comments
 (0)