[llvm-dev] Convert Function Pointer Call to Function Call at the IR Level

Ahmad Nouralizadeh Khorrami via llvm-dev llvm-dev at lists.llvm.org
Fri Aug 17 04:30:17 PDT 2018


Hi.
It seems that `struct.demuxer.2657*` is different from `struct.demuxer*`.
Should I add something like a `bitcast` before the call?
Thanks!

On 16 August 2018 at 15:45, Ahmad Nouralizadeh Khorrami <
ahmad.llvm at gmail.com> wrote:

> Hi,
> I want to convert a function pointer call in the IR of MPlayer to a
> function call. For example, I have the following line:
> ...
> %10 = tail call i32 %7(%struct.demuxer* nonnull %0, i32 %1, i8* %2) #7,
> !dbg !863222
> ...
> I want to set the target which is stored in %7 to a real function called
> "demux_lavf_control()" with the following definition:
> ...
> define internal i32 @demux_lavf_control(%struct.demuxer.2657* nocapture
> readonly, i32, i8* nocapture) #0 !dbg !963916 {
> ...
> I wrote a function pass and found the mentioned function pointer call
> (here, stored in "CallInstr") and set the call target as follows:
> ...
> Module *theModule = F.getParent();
> Function *targetFunc = theModule->getFunction("demux_lavf_control");
> CalIInstr->setCalledFunction(targetFunc);
> ...
> "F" is the function containing the call. But it leads to the following
> error:
> ...
> Call parameter type does not match function signature!
> %struct.demuxer* %0
>  %struct.demuxer.2657*  %10 = tail call i32 @demux_lavf_control(%struct.demuxer*
> nonnull %0, i32 %1, i8* %2) #7, !dbg !863222
> LLVM ERROR: Broken function found, compilation aborted!
> ...
> The [names:types] of call operands before the change is:
> ...
> [:%struct.demuxer*]
> [:i32]
> [:i8*]
> [:i32 (%struct.demuxer*, i32, i8*)*]
> ...
> And after the change is:
> ...
> [:%struct.demuxer*]
> [:i32]
> [:i8*]
> [demux_lavf_control:i32 (%struct.demuxer.2657*, i32, i8*)*]
> ...
> How can I solve the problem?
> Thanks in advance!
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180817/6f5f38dd/attachment.html>


More information about the llvm-dev mailing list