<div dir="ltr">I found this by setting a breakpoint on "llvm::CallInst::CallInst" and looking around at the two call instructions created in your example - it looks like Clang's IR generation tests whether the call is qualified to decide whether it can call virtually or not:<br><br><a href="https://github.com/llvm-mirror/clang/blob/master/lib/CodeGen/CGExprCXX.cpp#L197">https://github.com/llvm-mirror/clang/blob/master/lib/CodeGen/CGExprCXX.cpp#L197</a><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, May 28, 2020 at 4:35 PM Gregory Malecha via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><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" target="_blank">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"><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>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div>