<div dir="ltr">I'd bet that CreateLoad is returning non-null but the dyn_cast is returning null.<br><br>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)">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"> (</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)">%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">, </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)">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">)*) not a function itself. You shuold pass that (function pointer) to IRBuilder createCall - no need for the dyn_cast.</span></div><br><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">llvm-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 style="overflow-wrap: break-word;">Hi all,<div><br></div><div>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><br></div><div><br></div><div>Example IR generated (partially displayed below): <a href="https://github.com/mukul-rathi/bolt/blob/vtable/examples/vtable/foo.ll" target="_blank">https://github.com/mukul-rathi/bolt/blob/vtable/examples/vtable/foo.ll</a></div><div>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">https://github.com/mukul-rathi/bolt/blob/vtable/examples/vtable/foo.bolt</a></div><div><br></div><div><br></div><div>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">https://github.com/mukul-rathi/bolt/blob/vtable/src/llvm-backend/llvm_ir_codegen/class_codegen.cc#L57:L77</a>)</div><div> that generates the following global Vtable for a class Foo:</div><div><br></div><div><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)">%_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)"> = </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)">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)"> { </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)">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)"> (</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)">%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)">, </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)">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)">)* }</span></div><div><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)"><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"><tbody style="box-sizing:border-box"><tr style="box-sizing:border-box"></tr><tr style="box-sizing:border-box"><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"><span style="box-sizing:border-box;color:rgb(0,92,197)">%Foo</span> = <span style="box-sizing:border-box;color:rgb(215,58,73)">type</span> { <span style="box-sizing:border-box;color:rgb(215,58,73)">%_VtableFoo*</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)">%pthread_t*</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)">i32</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)">i32</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)">i32</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)">i32</span> }</td></tr><tr style="box-sizing:border-box"><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"><br></td></tr></tbody></table></span></div><div><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)"><tbody style="box-sizing:border-box"><tr style="box-sizing:border-box"></tr><tr style="box-sizing:border-box"><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"><span style="box-sizing:border-box;color:rgb(0,92,197)">@_VtableFoo</span> = <span style="box-sizing:border-box;color:rgb(215,58,73)">common</span> <span style="box-sizing:border-box;color:rgb(215,58,73)">global</span> <span style="box-sizing:border-box;color:rgb(0,92,197)">%_VtableFoo</span> { <span style="box-sizing:border-box;color:rgb(215,58,73)">void</span> (<span style="box-sizing:border-box;color:rgb(215,58,73)">%Foo*</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)">i32</span>)* <span style="box-sizing:border-box;color:rgb(0,92,197)">@_Foo__setgi</span> }</td></tr><tr style="box-sizing:border-box"><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"><br></td></tr></tbody></table></div></div><div>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">https://github.com/mukul-rathi/bolt/blob/vtable/src/llvm-backend/llvm_ir_codegen/expr_codegen.cc#L66:L89</a></div><div><br></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)"><tbody style="box-sizing:border-box"><tr style="box-sizing:border-box"><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">entry:</td></tr><tr style="box-sizing:border-box"><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"></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">  <span style="box-sizing:border-box;color:rgb(0,92,197)">%_var_y0</span> = <span style="box-sizing:border-box;color:rgb(215,58,73)">alloca</span> <span style="box-sizing:border-box;color:rgb(215,58,73)">%Foo*</span></td></tr><tr style="box-sizing:border-box"><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"></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">  <span style="box-sizing:border-box;color:rgb(0,92,197)">%0</span> = <span style="box-sizing:border-box;color:rgb(215,58,73)">call</span> <span style="box-sizing:border-box;color:rgb(215,58,73)">i8*</span> <span style="box-sizing:border-box;color:rgb(0,92,197)">@malloc</span>(<span style="box-sizing:border-box;color:rgb(215,58,73)">i64</span> <span style="box-sizing:border-box;color:rgb(215,58,73)">ptrtoint</span> (<span style="box-sizing:border-box;color:rgb(215,58,73)">%Foo*</span> <span style="box-sizing:border-box;color:rgb(215,58,73)">getelementptr</span> (<span style="box-sizing:border-box;color:rgb(0,92,197)">%Foo</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)">%Foo*</span> <span style="box-sizing:border-box;color:rgb(215,58,73)">null</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)">i64</span> <span style="box-sizing:border-box;color:rgb(0,92,197)">1</span>) <span style="box-sizing:border-box;color:rgb(215,58,73)">to</span> <span style="box-sizing:border-box;color:rgb(215,58,73)">i64</span>))</td></tr><tr style="box-sizing:border-box"><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"></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">  <span style="box-sizing:border-box;color:rgb(0,92,197)">%1</span> = <span style="box-sizing:border-box;color:rgb(215,58,73)">bitcast</span> <span style="box-sizing:border-box;color:rgb(215,58,73)">i8*</span> <span style="box-sizing:border-box;color:rgb(0,92,197)">%0</span> <span style="box-sizing:border-box;color:rgb(215,58,73)">to</span> <span style="box-sizing:border-box;color:rgb(215,58,73)">%Foo*</span></td></tr><tr style="box-sizing:border-box"><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"></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">  <span style="box-sizing:border-box;color:rgb(0,92,197)">%2</span> = <span style="box-sizing:border-box;color:rgb(215,58,73)">getelementptr</span> <span style="box-sizing:border-box;color:rgb(215,58,73)">inbounds</span> <span style="box-sizing:border-box;color:rgb(0,92,197)">%Foo</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)">%Foo*</span> <span style="box-sizing:border-box;color:rgb(0,92,197)">%1</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)">i32</span> <span style="box-sizing:border-box;color:rgb(0,92,197)">0</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)">i32</span> <span style="box-sizing:border-box;color:rgb(0,92,197)">0</span></td></tr><tr style="box-sizing:border-box"><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"></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">  <span style="box-sizing:border-box;color:rgb(215,58,73)">store</span> <span style="box-sizing:border-box;color:rgb(215,58,73)">%_VtableFoo*</span> <span style="box-sizing:border-box;color:rgb(0,92,197)">@_VtableFoo</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)">%_VtableFoo**</span> <span style="box-sizing:border-box;color:rgb(0,92,197)">%2</span></td></tr><tr style="box-sizing:border-box"><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"></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"><br></td></tr><tr style="box-sizing:border-box"><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"></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"><span style="box-sizing:border-box;color:rgb(0,92,197)">

<div style="color:rgb(0,0,0);font-family:Helvetica;white-space:normal">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"><span style="white-space:pre-wrap"><a href="https://github.com/mukul-rathi/bolt/blob/vtable/src/llvm-backend/llvm_ir_codegen/expr_codegen.cc#L188:L202" target="_blank">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="color:rgb(0,0,0);font-family:Helvetica;white-space:normal"><br></div><div style="color:rgb(0,0,0);font-family:Helvetica;white-space:normal"><br></div></span></td></tr><tr style="box-sizing:border-box"><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"></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">  <span style="box-sizing:border-box;color:rgb(0,92,197)">%5</span> = <span style="box-sizing:border-box;color:rgb(215,58,73)">load</span> <span style="box-sizing:border-box;color:rgb(215,58,73)">%Foo*</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)">%Foo**</span> <span style="box-sizing:border-box;color:rgb(0,92,197)">%_var_y0</span></td></tr><tr style="box-sizing:border-box"><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"></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">  <span style="box-sizing:border-box;color:rgb(0,92,197)">%6</span> = <span style="box-sizing:border-box;color:rgb(215,58,73)">getelementptr</span> <span style="box-sizing:border-box;color:rgb(215,58,73)">inbounds</span> <span style="box-sizing:border-box;color:rgb(0,92,197)">%Foo</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)">%Foo*</span> <span style="box-sizing:border-box;color:rgb(0,92,197)">%5</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)">i32</span> <span style="box-sizing:border-box;color:rgb(0,92,197)">0</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)">i32</span> <span style="box-sizing:border-box;color:rgb(0,92,197)">0</span></td></tr><tr style="box-sizing:border-box"><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"></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">  <span style="box-sizing:border-box;color:rgb(0,92,197)">%7</span> = <span style="box-sizing:border-box;color:rgb(215,58,73)">load</span> <span style="box-sizing:border-box;color:rgb(215,58,73)">%_VtableFoo*</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)">%_VtableFoo**</span> <span style="box-sizing:border-box;color:rgb(0,92,197)">%6</span></td></tr><tr style="box-sizing:border-box"><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"></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">  <span style="box-sizing:border-box;color:rgb(0,92,197)">%8</span> = <span style="box-sizing:border-box;color:rgb(215,58,73)">getelementptr</span> <span style="box-sizing:border-box;color:rgb(215,58,73)">inbounds</span> <span style="box-sizing:border-box;color:rgb(0,92,197)">%_VtableFoo</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)">%_VtableFoo*</span> <span style="box-sizing:border-box;color:rgb(0,92,197)">%7</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)">i32</span> <span style="box-sizing:border-box;color:rgb(0,92,197)">0</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)">i32</span> <span style="box-sizing:border-box;color:rgb(0,92,197)">0</span></td></tr><tr style="box-sizing:border-box"><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"></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">  <span style="box-sizing:border-box;color:rgb(0,92,197)">%9</span> = <span style="box-sizing:border-box;color:rgb(215,58,73)">load</span> <span style="box-sizing:border-box;color:rgb(215,58,73)">void</span> (<span style="box-sizing:border-box;color:rgb(215,58,73)">%Foo*</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)">i32</span>)*, <span style="box-sizing:border-box;color:rgb(215,58,73)">void</span> (<span style="box-sizing:border-box;color:rgb(215,58,73)">%Foo*</span>, <span style="box-sizing:border-box;color:rgb(215,58,73)">i32</span>)** <span style="box-sizing:border-box;color:rgb(0,92,197)">%8</span></td></tr><tr style="box-sizing:border-box"><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"></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"><br></td></tr></tbody></table><div><br></div><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)"><tbody style="box-sizing:border-box"><tr style="box-sizing:border-box"><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"></td></tr></tbody></table><div>However, the builder->CreateLoad instruction corresponding to the line with %9 returns null:</div></div><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)"><tbody style="box-sizing:border-box"><tr style="box-sizing:border-box"></tr><tr style="box-sizing:border-box"><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">      <span style="font-variant-ligatures:normal">llvm::Function *calleeMethod = </span>llvm::dyn_cast<llvm::Function>(builder-><span style="box-sizing:border-box;color:rgb(0,92,197)">CreateLoad</span>(calleeMethodPtr));
</td></tr><tr style="box-sizing:border-box"><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"></td></tr></tbody></table></div><div>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><br></div><div><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)"> 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)">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)">(calleeMethod, argVals);</span></div><div><div><font color="#24292e" face="SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace"><span style="white-space:pre-wrap;background-color:rgb(255,255,255)"><br></span></font></div><div><font color="#24292e" face="SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace"><span style="white-space:pre-wrap;background-color:rgb(255,255,255)"><br></span></font></div><div><div>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><br></div><div>I’d really appreciate any assistance.</div><div><br></div><div>Thanks,</div><div><br></div><div>Mukul</div><div><br></div></div><div><font color="#24292e" face="SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace"><span style="white-space:pre-wrap;background-color:rgb(255,255,255)"><br></span></font></div><div><font color="#24292e" face="SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace"><span style="white-space:pre-wrap;background-color:rgb(255,255,255)"><br></span></font></div><div><font color="#24292e" face="SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace"><span style="white-space:pre-wrap;background-color:rgb(255,255,255)"><br></span></font></div><div><br></div></div><div><br></div></div>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>