Skip to content

Commit

Permalink
Find module in build ptr to offset (#508)
Browse files Browse the repository at this point in the history
* BuildPointerToOffset assumes it makes progress

* Sort of fixes a bug in an API that should really be improved.
  • Loading branch information
Peter Goodman authored Apr 17, 2021
1 parent 3e31f2c commit f096390
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/BC/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2158,8 +2158,19 @@ llvm::Value *BuildPointerToOffset(llvm::IRBuilder<> &ir, llvm::Value *ptr,
llvm::Type *dest_ptr_type_) {

const auto block = ir.GetInsertBlock();
const auto module = block->getModule();
auto &context = block->getContext();
llvm::Module *module = nullptr;
if (block) {
module = block->getModule();
} else if (auto gv = llvm::dyn_cast<llvm::GlobalValue>(ptr); gv) {
module = gv->getParent();

// TODO(pag): Improve the API to take a `DataLayout`, perhaps.
} else {
LOG(FATAL)
<< "Unable to get the current module.";
}

auto &context = ptr->getContext();
const auto i32_type = llvm::Type::getInt32Ty(context);

const auto &dl = module->getDataLayout();
Expand Down

0 comments on commit f096390

Please sign in to comment.