Skip to content

Commit f096390

Browse files
author
Peter Goodman
authored
Find module in build ptr to offset (#508)
* BuildPointerToOffset assumes it makes progress * Sort of fixes a bug in an API that should really be improved.
1 parent 3e31f2c commit f096390

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

lib/BC/Util.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2158,8 +2158,19 @@ llvm::Value *BuildPointerToOffset(llvm::IRBuilder<> &ir, llvm::Value *ptr,
21582158
llvm::Type *dest_ptr_type_) {
21592159

21602160
const auto block = ir.GetInsertBlock();
2161-
const auto module = block->getModule();
2162-
auto &context = block->getContext();
2161+
llvm::Module *module = nullptr;
2162+
if (block) {
2163+
module = block->getModule();
2164+
} else if (auto gv = llvm::dyn_cast<llvm::GlobalValue>(ptr); gv) {
2165+
module = gv->getParent();
2166+
2167+
// TODO(pag): Improve the API to take a `DataLayout`, perhaps.
2168+
} else {
2169+
LOG(FATAL)
2170+
<< "Unable to get the current module.";
2171+
}
2172+
2173+
auto &context = ptr->getContext();
21632174
const auto i32_type = llvm::Type::getInt32Ty(context);
21642175

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

0 commit comments

Comments
 (0)