Skip to content

Commit

Permalink
Retrieve types properly from missing cases in FindVarInFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
tetsuo-cpp committed Jun 23, 2022
1 parent 67c5fd0 commit 669166d
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/BC/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,22 +218,20 @@ FindVarInFunction(llvm::BasicBlock *block, std::string_view name,
std::pair<llvm::Value *, llvm::Type *>
FindVarInFunction(llvm::Function *function, std::string_view name_,
bool allow_failure) {
// TODO(alex): Figure out how to to get types for the two cases below.
llvm::StringRef name(name_.data(), name_.size());
if (!function->empty()) {
for (auto &instr : function->getEntryBlock()) {
if (instr.getName() == name) {
return {&instr, nullptr};
if (auto *alloca = llvm::dyn_cast<llvm::AllocaInst>(&instr)) {
return {alloca, alloca->getAllocatedType()};
}
if (auto *gep = llvm::dyn_cast<llvm::GetElementPtrInst>(&instr)) {
return {gep, gep->getResultElementType()};
}
}
}
}

for (auto &arg : function->args()) {
if (arg.getName() == name) {
return {&arg, nullptr};
}
}

auto module = function->getParent();
if (auto var = module->getGlobalVariable(name)) {
return {var, var->getValueType()};
Expand Down

0 comments on commit 669166d

Please sign in to comment.