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

Keane, Erich via cfe-dev cfe-dev at lists.llvm.org
Fri May 15 06:48:01 PDT 2020


I don’t think this has anything to do with optimization.  If the type of the member expression base is completely known, it isn’t a dynamic call.

It seems that function (clang_Cursor_isDynamicCall is the one I found?) ends up calling MemberExpr->performsVirtualDispatch, which only considers AppleKext and full qualification.

I also note that the uses of performsVirtualDispatch calls getDevirutalizedMethod (https://clang.llvm.org/doxygen/DeclCXX_8cpp_source.html#l02107).

I presume “isDynamicCall” (or some similar function) should be checking whether it can be devirtualized like this before deciding it is a dynamic call.


From: cfe-dev <cfe-dev-bounces at lists.llvm.org> On Behalf Of Jonathan Coe via cfe-dev
Sent: Friday, May 15, 2020 6:37 AM
To: Borges, Matt <matt.borges at sap.com>
Cc: cfe-dev at lists.llvm.org
Subject: Re: [cfe-dev] clang_isDynamicCall always returns true for CallExpr which call virtual methods

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<mailto: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<mailto:matt.borges at sap.com>>
Date: Friday, May 8, 2020 at 11:36 AM
To: "cfe-dev at lists.llvm.org<mailto:cfe-dev at lists.llvm.org>" <cfe-dev at lists.llvm.org<mailto: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<mailto: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/3990fcce/attachment-0001.html>


More information about the cfe-dev mailing list