[cfe-dev] Dissect and rewrite of function calls in expressions

mats petersson via cfe-dev cfe-dev at lists.llvm.org
Tue Aug 8 03:43:25 PDT 2017


I would think (in fact, I _KNOW_) that the compiler already does the
transformation to temp1 = foo(42) and temp2 = foo(temp1) already. So it'd
just be a case, at the LLVM-IR level at least, to insert some code to
inspect temp1 and temp2.

Of course, it may be a slightly more interesting challenge to find your
"interesting functions" (particularly if interesting functions aren't a
well defined set of functions) when looking at the LLVM-IR - including the
fact that for example member functions gets mangled during compilation.

Also interesting/challenging is function pointers:

    pf = foo;
    var = 42 + pf(pf(42));

Consider where pf is passed into the function you're currently looking at,
or comes from a table of function pointers, with a non-constant determining
the index into the table.
A similar problem is of course virtual function calls - they are just
function pointer tables after all [but the table itself is the variable
part there, rather than the index, unless we're talking virtual member
function pointers, which isn't a common creature by any means]

--
Mats



On 7 August 2017 at 19:15, Marcel Schaible via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> Hi everyone,
>
> I need some advice for the following intended transformation:
>
> int foo(int p) { return 2*p; }
>
> int bar (void) {
>
>     int var = 42 + foo(foo(42)); /*1*/
>
>     return var;
>
> }
>
> I want to check the return value from foo:
>
> int bar (void) {
>
>     int temp1 = foo(42);
>
>     int temp2 foo(temp1);
>
>     // perform some checks on temp1 and temp2
>
>     int var = 42 + temp2;
>
>     return var;
>
> }
>
> How should I dissect and translate the expr /*1*/ with a Rewriter?
>
> Thanks for your help
>
> Marcel
>
> (Greetings from the Black Forest in Germany ;- ) )
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170808/cd55e872/attachment.html>


More information about the cfe-dev mailing list