<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Thanks David, that makes sense, I’d hadn’t realised the function had to be known at compile-time.<div class=""><br class=""></div><div class="">It now works as expected, thank you!<br class=""><div class=""><br class=""></div><div class="">Mukul<br class=""><div class=""><div class=""><br class=""></div><div class=""><br class=""><div class=""><div class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 10 Jun 2020, at 18:35, David Blaikie <<a href="mailto:dblaikie@gmail.com" class="">dblaikie@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">I'd bet that CreateLoad is returning non-null but the dyn_cast is returning null.<br class=""><br class="">llvm::Function represents a specific function known at compile-time. You have loaded a function pointer (<span style="font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre-wrap;box-sizing:border-box;color:rgb(215,58,73)" class="">void</span><span style="color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre-wrap" class=""> (</span><span style="font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre-wrap;box-sizing:border-box;color:rgb(215,58,73)" class="">%Foo*</span><span style="color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre-wrap" class="">, </span><span style="font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre-wrap;box-sizing:border-box;color:rgb(215,58,73)" class="">i32</span><span style="color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre-wrap" class="">)*) not a function itself. You shuold pass that (function pointer) to IRBuilder createCall - no need for the dyn_cast.</span></div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jun 10, 2020 at 10:01 AM Mukul Rathi via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;" class="">Hi all,<div class=""><br class=""></div><div class="">I’ve been working on a Java-esque object-oriented language Bolt that targets LLVM IR.  I’m agonisingly close to getting a virtual table working, and was hoping one of you could point out the gap in my understanding. I’ve linked the C++ code snippets relevant to the vtable below. </div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Example IR generated (partially displayed below): <a href="https://github.com/mukul-rathi/bolt/blob/vtable/examples/vtable/foo.ll" target="_blank" class="">https://github.com/mukul-rathi/bolt/blob/vtable/examples/vtable/foo.ll</a></div><div class="">And the Bolt source code that compiles to it- <a href="https://github.com/mukul-rathi/bolt/blob/vtable/examples/vtable/foo.bolt" target="_blank" class="">https://github.com/mukul-rathi/bolt/blob/vtable/examples/vtable/foo.bolt</a></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">I currently have code (<a href="https://github.com/mukul-rathi/bolt/blob/vtable/src/llvm-backend/llvm_ir_codegen/class_codegen.cc#L57:L77" target="_blank" class="">https://github.com/mukul-rathi/bolt/blob/vtable/src/llvm-backend/llvm_ir_codegen/class_codegen.cc#L57:L77</a>)</div><div class=""> that generates the following global Vtable for a class Foo:</div><div class=""><br class=""></div><div class=""><span style="box-sizing:border-box;color:rgb(0,92,197);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-variant-ligatures:normal;white-space:pre-wrap;background-color:rgb(255,255,255)" class="">%_VtableFoo</span><span style="color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-variant-ligatures:normal;white-space:pre-wrap;background-color:rgb(255,255,255)" class=""> = </span><span style="box-sizing:border-box;color:rgb(215,58,73);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-variant-ligatures:normal;white-space:pre-wrap;background-color:rgb(255,255,255)" class="">type</span><span style="color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-variant-ligatures:normal;white-space:pre-wrap;background-color:rgb(255,255,255)" class=""> { </span><span style="box-sizing:border-box;color:rgb(215,58,73);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-variant-ligatures:normal;white-space:pre-wrap;background-color:rgb(255,255,255)" class="">void</span><span style="color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-variant-ligatures:normal;white-space:pre-wrap;background-color:rgb(255,255,255)" class=""> (</span><span style="box-sizing:border-box;color:rgb(215,58,73);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-variant-ligatures:normal;white-space:pre-wrap;background-color:rgb(255,255,255)" class="">%Foo*</span><span style="color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-variant-ligatures:normal;white-space:pre-wrap;background-color:rgb(255,255,255)" class="">, </span><span style="box-sizing:border-box;color:rgb(215,58,73);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-variant-ligatures:normal;white-space:pre-wrap;background-color:rgb(255,255,255)" class="">i32</span><span style="color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-variant-ligatures:normal;white-space:pre-wrap;background-color:rgb(255,255,255)" class="">)* }</span></div><div class=""><span style="color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-variant-ligatures:normal;white-space:pre-wrap;background-color:rgb(255,255,255)" class=""><table style="box-sizing:border-box;border-spacing:0px;border-collapse:collapse;color:rgb(36,41,46);font-family:-apple-system,system-ui,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji";font-size:14px" class=""><tbody style="box-sizing:border-box" class=""><tr style="box-sizing:border-box" class=""></tr><tr style="box-sizing:border-box" class=""><td id="gmail-m_-2279537516446150519LC6" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre-wrap" class=""><span style="box-sizing:border-box;color:rgb(0,92,197)" class="">%Foo</span> = <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">type</span> { <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">%_VtableFoo*</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">%pthread_t*</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">i32</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">i32</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">i32</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">i32</span> }</td></tr><tr style="box-sizing:border-box" class=""><td id="gmail-m_-2279537516446150519L7" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;line-height:20px;color:rgba(27,31,35,0.3);text-align:right;white-space:nowrap;vertical-align:top" class=""><br class=""></td></tr></tbody></table></span></div><div class=""><div class=""><table style="box-sizing:border-box;border-spacing:0px;border-collapse:collapse;color:rgb(36,41,46);font-family:-apple-system,system-ui,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji";font-size:14px;background-color:rgb(255,255,255)" class=""><tbody style="box-sizing:border-box" class=""><tr style="box-sizing:border-box" class=""></tr><tr style="box-sizing:border-box" class=""><td id="gmail-m_-2279537516446150519LC9" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre-wrap" class=""><span style="box-sizing:border-box;color:rgb(0,92,197)" class="">@_VtableFoo</span> = <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">common</span> <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">global</span> <span style="box-sizing:border-box;color:rgb(0,92,197)" class="">%_VtableFoo</span> { <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">void</span> (<span style="box-sizing:border-box;color:rgb(215,58,73)" class="">%Foo*</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">i32</span>)* <span style="box-sizing:border-box;color:rgb(0,92,197)" class="">@_Foo__setgi</span> }</td></tr><tr style="box-sizing:border-box" class=""><td id="gmail-m_-2279537516446150519L10" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;line-height:20px;color:rgba(27,31,35,0.3);text-align:right;white-space:nowrap;vertical-align:top" class=""><br class=""></td></tr></tbody></table></div></div><div class="">The code for instantiating the table seems to generate the correct IR (create an object, store a pointer to its vtable) - <a href="https://github.com/mukul-rathi/bolt/blob/vtable/src/llvm-backend/llvm_ir_codegen/expr_codegen.cc#L66:L89" target="_blank" class="">https://github.com/mukul-rathi/bolt/blob/vtable/src/llvm-backend/llvm_ir_codegen/expr_codegen.cc#L66:L89</a></div><div class=""><br class=""></div><table style="box-sizing:border-box;border-spacing:0px;border-collapse:collapse;color:rgb(36,41,46);font-family:-apple-system,system-ui,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji";font-size:14px;background-color:rgb(255,255,255)" class=""><tbody style="box-sizing:border-box" class=""><tr style="box-sizing:border-box" class=""><td id="gmail-m_-2279537516446150519LC37" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre-wrap" class="">entry:</td></tr><tr style="box-sizing:border-box" class=""><td id="gmail-m_-2279537516446150519L38" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;line-height:20px;color:rgba(27,31,35,0.3);text-align:right;white-space:nowrap;vertical-align:top" class=""></td><td id="gmail-m_-2279537516446150519LC38" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre-wrap" class="">  <span style="box-sizing:border-box;color:rgb(0,92,197)" class="">%_var_y0</span> = <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">alloca</span> <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">%Foo*</span></td></tr><tr style="box-sizing:border-box" class=""><td id="gmail-m_-2279537516446150519L39" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;line-height:20px;color:rgba(27,31,35,0.3);text-align:right;white-space:nowrap;vertical-align:top" class=""></td><td id="gmail-m_-2279537516446150519LC39" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre-wrap" class="">  <span style="box-sizing:border-box;color:rgb(0,92,197)" class="">%0</span> = <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">call</span> <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">i8*</span> <span style="box-sizing:border-box;color:rgb(0,92,197)" class="">@malloc</span>(<span style="box-sizing:border-box;color:rgb(215,58,73)" class="">i64</span> <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">ptrtoint</span> (<span style="box-sizing:border-box;color:rgb(215,58,73)" class="">%Foo*</span> <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">getelementptr</span> (<span style="box-sizing:border-box;color:rgb(0,92,197)" class="">%Foo</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">%Foo*</span> <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">null</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">i64</span> <span style="box-sizing:border-box;color:rgb(0,92,197)" class="">1</span>) <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">to</span> <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">i64</span>))</td></tr><tr style="box-sizing:border-box" class=""><td id="gmail-m_-2279537516446150519L40" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;line-height:20px;color:rgba(27,31,35,0.3);text-align:right;white-space:nowrap;vertical-align:top" class=""></td><td id="gmail-m_-2279537516446150519LC40" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre-wrap" class="">  <span style="box-sizing:border-box;color:rgb(0,92,197)" class="">%1</span> = <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">bitcast</span> <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">i8*</span> <span style="box-sizing:border-box;color:rgb(0,92,197)" class="">%0</span> <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">to</span> <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">%Foo*</span></td></tr><tr style="box-sizing:border-box" class=""><td id="gmail-m_-2279537516446150519L41" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;line-height:20px;color:rgba(27,31,35,0.3);text-align:right;white-space:nowrap;vertical-align:top" class=""></td><td id="gmail-m_-2279537516446150519LC41" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre-wrap" class="">  <span style="box-sizing:border-box;color:rgb(0,92,197)" class="">%2</span> = <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">getelementptr</span> <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">inbounds</span> <span style="box-sizing:border-box;color:rgb(0,92,197)" class="">%Foo</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">%Foo*</span> <span style="box-sizing:border-box;color:rgb(0,92,197)" class="">%1</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">i32</span> <span style="box-sizing:border-box;color:rgb(0,92,197)" class="">0</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">i32</span> <span style="box-sizing:border-box;color:rgb(0,92,197)" class="">0</span></td></tr><tr style="box-sizing:border-box" class=""><td id="gmail-m_-2279537516446150519L42" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;line-height:20px;color:rgba(27,31,35,0.3);text-align:right;white-space:nowrap;vertical-align:top" class=""></td><td id="gmail-m_-2279537516446150519LC42" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre-wrap" class="">  <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">store</span> <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">%_VtableFoo*</span> <span style="box-sizing:border-box;color:rgb(0,92,197)" class="">@_VtableFoo</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">%_VtableFoo**</span> <span style="box-sizing:border-box;color:rgb(0,92,197)" class="">%2</span></td></tr><tr style="box-sizing:border-box" class=""><td id="gmail-m_-2279537516446150519L43" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;line-height:20px;color:rgba(27,31,35,0.3);text-align:right;white-space:nowrap;vertical-align:top" class=""></td><td id="gmail-m_-2279537516446150519LC43" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre-wrap" class=""><br class=""></td></tr><tr style="box-sizing:border-box" class=""><td id="gmail-m_-2279537516446150519L47" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;line-height:20px;color:rgba(27,31,35,0.3);text-align:right;white-space:nowrap;vertical-align:top" class=""></td><td id="gmail-m_-2279537516446150519LC47" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre-wrap" class=""><span style="box-sizing:border-box;color:rgb(0,92,197)" class="">

<div style="font-family: Helvetica; white-space: normal;" class="">The issue is when it comes to actually calling the method. Up to this point, the code generates the expected IR (<font face="SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace" class=""><span style="white-space:pre-wrap" class=""><a href="https://github.com/mukul-rathi/bolt/blob/vtable/src/llvm-backend/llvm_ir_codegen/expr_codegen.cc#L188:L202" target="_blank" class="">https://github.com/mukul-rathi/bolt/blob/vtable/src/llvm-backend/llvm_ir_codegen/expr_codegen.cc#L188:L202</a></span></font>)</div><div style="font-family: Helvetica; white-space: normal;" class=""><br class=""></div><div style="font-family: Helvetica; white-space: normal;" class=""><br class=""></div></span></td></tr><tr style="box-sizing:border-box" class=""><td id="gmail-m_-2279537516446150519L48" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;line-height:20px;color:rgba(27,31,35,0.3);text-align:right;white-space:nowrap;vertical-align:top" class=""></td><td id="gmail-m_-2279537516446150519LC48" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre-wrap" class="">  <span style="box-sizing:border-box;color:rgb(0,92,197)" class="">%5</span> = <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">load</span> <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">%Foo*</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">%Foo**</span> <span style="box-sizing:border-box;color:rgb(0,92,197)" class="">%_var_y0</span></td></tr><tr style="box-sizing:border-box" class=""><td id="gmail-m_-2279537516446150519L49" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;line-height:20px;color:rgba(27,31,35,0.3);text-align:right;white-space:nowrap;vertical-align:top" class=""></td><td id="gmail-m_-2279537516446150519LC49" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre-wrap" class="">  <span style="box-sizing:border-box;color:rgb(0,92,197)" class="">%6</span> = <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">getelementptr</span> <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">inbounds</span> <span style="box-sizing:border-box;color:rgb(0,92,197)" class="">%Foo</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">%Foo*</span> <span style="box-sizing:border-box;color:rgb(0,92,197)" class="">%5</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">i32</span> <span style="box-sizing:border-box;color:rgb(0,92,197)" class="">0</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">i32</span> <span style="box-sizing:border-box;color:rgb(0,92,197)" class="">0</span></td></tr><tr style="box-sizing:border-box" class=""><td id="gmail-m_-2279537516446150519L50" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;line-height:20px;color:rgba(27,31,35,0.3);text-align:right;white-space:nowrap;vertical-align:top" class=""></td><td id="gmail-m_-2279537516446150519LC50" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre-wrap" class="">  <span style="box-sizing:border-box;color:rgb(0,92,197)" class="">%7</span> = <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">load</span> <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">%_VtableFoo*</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">%_VtableFoo**</span> <span style="box-sizing:border-box;color:rgb(0,92,197)" class="">%6</span></td></tr><tr style="box-sizing:border-box" class=""><td id="gmail-m_-2279537516446150519L51" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;line-height:20px;color:rgba(27,31,35,0.3);text-align:right;white-space:nowrap;vertical-align:top" class=""></td><td id="gmail-m_-2279537516446150519LC51" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre-wrap" class="">  <span style="box-sizing:border-box;color:rgb(0,92,197)" class="">%8</span> = <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">getelementptr</span> <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">inbounds</span> <span style="box-sizing:border-box;color:rgb(0,92,197)" class="">%_VtableFoo</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">%_VtableFoo*</span> <span style="box-sizing:border-box;color:rgb(0,92,197)" class="">%7</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">i32</span> <span style="box-sizing:border-box;color:rgb(0,92,197)" class="">0</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">i32</span> <span style="box-sizing:border-box;color:rgb(0,92,197)" class="">0</span></td></tr><tr style="box-sizing:border-box" class=""><td id="gmail-m_-2279537516446150519L52" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;line-height:20px;color:rgba(27,31,35,0.3);text-align:right;white-space:nowrap;vertical-align:top" class=""></td><td id="gmail-m_-2279537516446150519LC52" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre-wrap" class="">  <span style="box-sizing:border-box;color:rgb(0,92,197)" class="">%9</span> = <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">load</span> <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">void</span> (<span style="box-sizing:border-box;color:rgb(215,58,73)" class="">%Foo*</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">i32</span>)*, <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">void</span> (<span style="box-sizing:border-box;color:rgb(215,58,73)" class="">%Foo*</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)" class="">i32</span>)** <span style="box-sizing:border-box;color:rgb(0,92,197)" class="">%8</span></td></tr><tr style="box-sizing:border-box" class=""><td id="gmail-m_-2279537516446150519L53" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;line-height:20px;color:rgba(27,31,35,0.3);text-align:right;white-space:nowrap;vertical-align:top" class=""></td><td id="gmail-m_-2279537516446150519LC53" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre-wrap" class=""><br class=""></td></tr></tbody></table><div class=""><br class=""></div><div class=""><table style="box-sizing:border-box;border-spacing:0px;border-collapse:collapse;color:rgb(36,41,46);font-family:-apple-system,system-ui,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji";font-size:14px;background-color:rgb(255,255,255)" class=""><tbody style="box-sizing:border-box" class=""><tr style="box-sizing:border-box" class=""><td id="gmail-m_-2279537516446150519L51" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;line-height:20px;color:rgba(27,31,35,0.3);text-align:right;white-space:nowrap;vertical-align:top" class=""></td></tr></tbody></table><div class="">However, the builder->CreateLoad instruction corresponding to the line with %9 returns null:</div></div><div class=""><table style="box-sizing:border-box;border-spacing:0px;border-collapse:collapse;color:rgb(36,41,46);font-family:-apple-system,system-ui,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji";font-size:14px;background-color:rgb(255,255,255)" class=""><tbody style="box-sizing:border-box" class=""><tr style="box-sizing:border-box" class=""></tr><tr style="box-sizing:border-box" class=""><td id="gmail-m_-2279537516446150519LC202" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre-wrap" class="">      <span style="font-variant-ligatures:normal" class="">llvm::Function *calleeMethod = </span>llvm::dyn_cast<llvm::Function>(builder-><span style="box-sizing:border-box;color:rgb(0,92,197)" class="">CreateLoad</span>(calleeMethodPtr));
</td></tr><tr style="box-sizing:border-box" class=""><td id="gmail-m_-2279537516446150519L203" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;line-height:20px;color:rgba(27,31,35,0.3);text-align:right;white-space:nowrap;vertical-align:top" class=""></td></tr></tbody></table></div><div class="">So if I then try to execute the following builder->CreateCall function I end up with a segmentation fault since calleeMethod is null:</div><div class=""><br class=""></div><div class=""><span style="color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-variant-ligatures:normal;white-space:pre-wrap;background-color:rgb(255,255,255)" class=""> builder-></span><span style="box-sizing:border-box;color:rgb(0,92,197);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-variant-ligatures:normal;white-space:pre-wrap;background-color:rgb(255,255,255)" class="">CreateCall</span><span style="color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-variant-ligatures:normal;white-space:pre-wrap;background-color:rgb(255,255,255)" class="">(calleeMethod, argVals);</span></div><div class=""><div class=""><font color="#24292e" face="SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace" class=""><span style="white-space:pre-wrap;background-color:rgb(255,255,255)" class=""><br class=""></span></font></div><div class=""><font color="#24292e" face="SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace" class=""><span style="white-space:pre-wrap;background-color:rgb(255,255,255)" class=""><br class=""></span></font></div><div class=""><div class="">Under what circumstances would builder->CreateLoad return null?  Is the global vTable's memory not allocated correctly? Or have I been approaching this incorrectly - is there another method in the C++ API that I should be using for indirect function calls?</div><div class=""><br class=""></div><div class="">I’d really appreciate any assistance.</div><div class=""><br class=""></div><div class="">Thanks,</div><div class=""><br class=""></div><div class="">Mukul</div><div class=""><br class=""></div></div><div class=""><font color="#24292e" face="SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace" class=""><span style="white-space:pre-wrap;background-color:rgb(255,255,255)" class=""><br class=""></span></font></div><div class=""><font color="#24292e" face="SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace" class=""><span style="white-space:pre-wrap;background-color:rgb(255,255,255)" class=""><br class=""></span></font></div><div class=""><font color="#24292e" face="SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace" class=""><span style="white-space:pre-wrap;background-color:rgb(255,255,255)" class=""><br class=""></span></font></div><div class=""><br class=""></div></div><div class=""><br class=""></div></div>_______________________________________________<br class="">
LLVM Developers mailing list<br class="">
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a><br class="">
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank" class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br class="">
</blockquote></div>
</div></blockquote></div><br class=""></div></div></div></div></div></div></body></html>