From f04dea76364a1428f5ef8d4ecc9c2722d90f9934 Mon Sep 17 00:00:00 2001 From: Pietro Fezzardi Date: Thu, 20 Jul 2023 17:16:58 +0200 Subject: [PATCH] InitModelTypes: detect type for isolated callees Before this commit initModelTypes wasn't able to detect the type of the callee operand for calls to isolated functions. This commit properly supports this case. --- lib/InitModelTypes/InitModelTypes.cpp | 29 +++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/InitModelTypes/InitModelTypes.cpp b/lib/InitModelTypes/InitModelTypes.cpp index 16b904d53..db70082b1 100644 --- a/lib/InitModelTypes/InitModelTypes.cpp +++ b/lib/InitModelTypes/InitModelTypes.cpp @@ -334,12 +334,29 @@ ModelTypesMap initModelTypes(FunctionMetadataCache &Cache, const auto *InstType = I.getType(); - // Visit operands, in case they are constants, globals or constexprs - for (const llvm::Value *Op : I.operand_values()) { - // Ignore operands of some custom opcodes - if (isCallTo(&I, "revng_call_stack_arguments")) - continue; - addOperandType(Op, Model, TypeMap, PointersOnly); + // Ignore operands of some custom opcodes + if (not isCallTo(&I, "revng_call_stack_arguments")) { + // Visit operands, in case they are constants, globals or constexprs + for (const llvm::Use &Op : I.operands()) { + + if (auto *Call = getCallToIsolatedFunction(&I); + Call and Call->isCallee(&Op)) { + // Isolated functions have their prototype in the model + // + // If it's a direct call to an isolated function we know the type of + // the function, which affects the type of the + auto *Called = Call->getCalledOperand(); + if (auto *CalledFunction = dyn_cast(Called)) { + auto Prototype = Cache.getCallSitePrototype(Model, Call); + revng_assert(Prototype.isValid() and not Prototype.empty()); + TypeMap.insert({ CalledFunction, + createPointerTo(Prototype, Model) }); + continue; + } + } + + addOperandType(Op, Model, TypeMap, PointersOnly); + } } // Insert void types for consistency