[cfe-dev] clang_isDynamicCall always returns true for CallExpr which call virtual methods

Jonathan Coe via cfe-dev cfe-dev at lists.llvm.org
Fri May 15 06:37:03 PDT 2020


I guess that clang_isDynamicCall is not concerned with function calls that
can be de-virtualised through optimisation (albeit fairly trivial
optimisation).

I'm interested to know how you could, in general, find out when a method
will be called polymorphically but would guess that it's very hard as
cross-translation unit optimisation (WPO) would have an effect. Clang's AST
won't have access ot the info needed to determine this (as far as I know).

Please keep me posted on progress!

Jon

On Fri, 15 May 2020 at 14:28, Borges, Matt via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> Hi,
>
>
>
> Just resending.  If I am asking this question on the wrong mailing list,
> please le me know.
>
>
>
> Thanks,
>
> Matt
>
>
>
> *From: *Matt Borges <matt.borges at sap.com>
> *Date: *Friday, May 8, 2020 at 11:36 AM
> *To: *"cfe-dev at lists.llvm.org" <cfe-dev at lists.llvm.org>
> *Subject: *clang_isDynamicCall always returns true for CallExpr which
> call virtual methods
>
>
>
> Hi,
>
>
>
> I’m visiting the AST of this simple code with libclang:
>
> class Base
>
> {
>
>     public:
>
>         virtual void Print() {}
>
> };
>
>
>
> class Derived : public Base
>
> {
>
>     public:
>
>         virtual void Print() {}
>
> };
>
>
>
> void func1( Base * b )
>
> {
>
>     b->Print();
>
> }
>
>
>
> void func2( Base b )
>
> {
>
>     b.Print();
>
> }
>
>
>
> void func3( Base & b )
>
> {
>
>     b.Print();
>
> }
>
>
>
> clang_isDynamicCall returns true for all three CallExpr cursors in the
> code.  I would have expected clang_isDynamicCall to return false for the
> call in func2 because the call is definitely to the Print method of Base.
> Is this intended behaviour?  If yes, is there another way to determine
> whether the function call is going to be made polymorphically?
>
>
>
> Thanks in advance,
>
> Matt
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://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/20200515/637e41d0/attachment.html>


More information about the cfe-dev mailing list