Skip to content

Commit

Permalink
param_return: connect wrappers more intelligently
Browse files Browse the repository at this point in the history
Sometimes wrapper detection might be only partialy right.
In such cases we would like to find wheter arguments
are already handled by analysis and not change them.

For example this will enable test: derived-diamond.arm.clang.O1.elf
in `features/cpp/derived-diamond/symbols`.
  • Loading branch information
Peter Kubov committed Aug 2, 2020
1 parent 61af12f commit e85b7da
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/bin2llvmir/optimizations/param_return/param_return.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1059,8 +1059,32 @@ void ParamReturn::connectWrappers(const DataFlowEntry& de)
unsigned i = 0;
for (auto& a : fnc->args())
{
auto* conv = IrModifier::convertValueToType(&a, wrappedCall->getArgOperand(i)->getType(), wrappedCall);
wrappedCall->setArgOperand(i++, conv);
auto iarg = wrappedCall->getArgOperand(i);
bool shouldSkip = false;
if (auto* load = dyn_cast<LoadInst>(llvm_utils::skipCasts(iarg))) {
auto oldarg = load->getPointerOperand();

std::vector<StoreInst*> users;
for (const auto& U : oldarg->users())
{
if (auto* store = dyn_cast<StoreInst>(U)) {
if (store->getFunction() == fnc)
users.push_back(store);
}
}
for (auto store: users) {
if (llvm_utils::skipCasts(store->getValueOperand()) == &a)
continue;

shouldSkip = true;
}
}

if (!shouldSkip) {
auto* conv = IrModifier::convertValueToType(&a, wrappedCall->getArgOperand(i)->getType(), wrappedCall);
wrappedCall->setArgOperand(i, conv);
}
i++;
}

//
Expand Down

0 comments on commit e85b7da

Please sign in to comment.