Skip to content

Commit

Permalink
bin2llvmir: check data types before using them in functions and allocas
Browse files Browse the repository at this point in the history
fix #535
  • Loading branch information
PeterMatula committed Jun 25, 2019
1 parent cb771a6 commit bebaf4d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/bin2llvmir/optimizations/value_protect/value_protect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,10 @@ void ValueProtect::protectValue(
llvm::Instruction* before)
{
Function* fnc = getOrCreateFunction(t);
if (fnc == nullptr)
{
return;
}
auto* c = CallInst::Create(fnc);
c->insertBefore(before);
auto* s = new StoreInst(c, val);
Expand Down Expand Up @@ -553,6 +557,11 @@ llvm::Function* ValueProtect::getOrCreateFunction(llvm::Type* t)

llvm::Function* ValueProtect::createFunction(llvm::Type* t)
{
if (!FunctionType::isValidReturnType(t))
{
return nullptr;
}

FunctionType* ft = FunctionType::get(t, false);
auto* fnc = Function::Create(
ft,
Expand Down
2 changes: 1 addition & 1 deletion src/bin2llvmir/utils/ir_modifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ IrModifier::StackPair IrModifier::getStackVariable(
llvm::Type* type,
const std::string& name)
{
if (!PointerType::isValidElementType(type))
if (!PointerType::isValidElementType(type) || !type->isSized())
{
type = Abi::getDefaultType(fnc->getParent());
}
Expand Down

0 comments on commit bebaf4d

Please sign in to comment.