<div dir="ltr">Hello --<div><br></div><div>I'm working on a tool that gives a formal semantics to the clang C++ abstract syntax tree (the project is available here: <a href="http://github.com/bedrocksystems/cpp2v">github.com/bedrocksystems/cpp2v</a>). I'm working on adding support for virtual functions and I'm trying to understand whether a call in the AST is a static call or a dynamic call and I'm having difficulty figuring out how to do it reliably. Here's a simple program:</div><div><br></div><font face="monospace">struct A {</font><div><font face="monospace">  virtual int foo() { return 100; }</font></div><div><font face="monospace">};</font><div><font face="monospace">struct B : public A {</font></div><div><font face="monospace">  virtual int foo() { return 10; }</font></div><div><font face="monospace">};</font></div><div><font face="monospace">int test(B* b) {</font></div><div><font face="monospace">  return b->foo() + b->B::foo();</font></div><div><font face="monospace">}</font><div><br></div><div>From what I understand (and what the compiler does) the left call `b->foo()` uses dynamic dispatch to resolve `foo` in the most derived class of the argument B. But the call on the right always calls B::foo (returning 10) regardless of the most derived class of B. However, I don't understand what function I can call on the CXXMemberCallExpr node that distinguishes these two cases. getMethodDecl, getRecordDecl, and getImplicitObjectArgument all seem to return the exact same information.</div><div><br></div><div>How does clang differentiate between these two calls in order to get the correct behavior?</div><div><div><br></div><div>Thanks in advance for any pointers.</div><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>gregory malecha</div><div><a href="https://gmalecha.github.io" target="_blank">gmalecha.github.io</a></div></div></div></div></div></div></div></div></div>