<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="">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" 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" 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" 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 class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197); font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-variant-ligatures: normal; orphans: 2; white-space: pre; widows: 2; 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; orphans: 2; white-space: pre; widows: 2; background-color: rgb(255, 255, 255);" class=""> = </span><span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73); font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-variant-ligatures: normal; orphans: 2; white-space: pre; widows: 2; 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; orphans: 2; white-space: pre; widows: 2; background-color: rgb(255, 255, 255);" class=""> { </span><span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73); font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-variant-ligatures: normal; orphans: 2; white-space: pre; widows: 2; 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; orphans: 2; white-space: pre; widows: 2; background-color: rgb(255, 255, 255);" class=""> (</span><span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73); font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-variant-ligatures: normal; orphans: 2; white-space: pre; widows: 2; 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; orphans: 2; white-space: pre; widows: 2; background-color: rgb(255, 255, 255);" class="">, </span><span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73); font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-variant-ligatures: normal; orphans: 2; white-space: pre; widows: 2; 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; orphans: 2; white-space: pre; widows: 2; 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; orphans: 2; white-space: pre; widows: 2; background-color: rgb(255, 255, 255);" class=""><table class="js-file-line-container highlight tab-size" data-tab-size="8" data-paste-markdown-skip="" style="box-sizing: border-box; border-spacing: 0px; border-collapse: collapse; tab-size: 8; 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;" class=""><tr style="box-sizing: border-box;" class=""></tr><tr style="box-sizing: border-box;" class=""><td id="LC6" class="js-file-line blob-code-inner blob-code" style="box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-size: 12px; overflow-wrap: normal; white-space: pre;"><span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">%Foo</span> = <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">type</span> { <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">%_VtableFoo*</span>, <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">%pthread_t*</span>, <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">i32</span>, <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">i32</span>, <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">i32</span>, <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">i32</span> }</td></tr><tr style="box-sizing: border-box;" class=""><td id="L7" class="blob-num js-line-number" data-line-number="7" 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; cursor: pointer; user-select: none;"><br class=""></td></tr></tbody></table></span></div><div class=""><div class=""><table class="js-file-line-container highlight tab-size" data-tab-size="8" data-paste-markdown-skip="" style="box-sizing: border-box; border-spacing: 0px; border-collapse: collapse; tab-size: 8; 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; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);"><tbody style="box-sizing: border-box;" class=""><tr style="box-sizing: border-box;" class=""></tr><tr style="box-sizing: border-box;" class=""><td id="LC9" class="js-file-line blob-code-inner blob-code" style="box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-size: 12px; overflow-wrap: normal; white-space: pre;"><span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">@_VtableFoo</span> = <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">common</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">global</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">%_VtableFoo</span> { <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">void</span> (<span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">%Foo*</span>, <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">i32</span>)* <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">@_Foo__setgi</span> }</td></tr><tr style="box-sizing: border-box;" class=""><td id="L10" class="blob-num js-line-number" data-line-number="10" 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; cursor: pointer; user-select: none;"><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" 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 class="js-file-line-container highlight tab-size" data-tab-size="8" data-paste-markdown-skip="" style="box-sizing: border-box; border-spacing: 0px; border-collapse: collapse; tab-size: 8; 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; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);"><tbody style="box-sizing: border-box;" class=""><tr style="box-sizing: border-box;" class=""><td id="LC37" class="js-file-line blob-code-inner blob-code" style="box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-size: 12px; overflow-wrap: normal; white-space: pre;">entry:</td></tr><tr style="box-sizing: border-box;" class=""><td id="L38" class="blob-num js-line-number" data-line-number="38" 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; cursor: pointer; user-select: none;"></td><td id="LC38" class="js-file-line blob-code-inner blob-code" style="box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-size: 12px; overflow-wrap: normal; white-space: pre;">  <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">%_var_y0</span> = <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">alloca</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">%Foo*</span></td></tr><tr style="box-sizing: border-box;" class=""><td id="L39" class="blob-num js-line-number" data-line-number="39" 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; cursor: pointer; user-select: none;"></td><td id="LC39" class="js-file-line blob-code-inner blob-code" style="box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-size: 12px; overflow-wrap: normal; white-space: pre;">  <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">%0</span> = <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">call</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">i8*</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">@malloc</span>(<span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">i64</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">ptrtoint</span> (<span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">%Foo*</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">getelementptr</span> (<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">%Foo</span>, <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">%Foo*</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">null</span>, <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">i64</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">1</span>) <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">to</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">i64</span>))</td></tr><tr style="box-sizing: border-box;" class=""><td id="L40" class="blob-num js-line-number" data-line-number="40" 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; cursor: pointer; user-select: none;"></td><td id="LC40" class="js-file-line blob-code-inner blob-code" style="box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-size: 12px; overflow-wrap: normal; white-space: pre;">  <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">%1</span> = <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">bitcast</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">i8*</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">%0</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">to</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">%Foo*</span></td></tr><tr style="box-sizing: border-box;" class=""><td id="L41" class="blob-num js-line-number" data-line-number="41" 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; cursor: pointer; user-select: none;"></td><td id="LC41" class="js-file-line blob-code-inner blob-code" style="box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-size: 12px; overflow-wrap: normal; white-space: pre;">  <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">%2</span> = <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">getelementptr</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">inbounds</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">%Foo</span>, <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">%Foo*</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">%1</span>, <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">i32</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">0</span>, <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">i32</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">0</span></td></tr><tr style="box-sizing: border-box;" class=""><td id="L42" class="blob-num js-line-number" data-line-number="42" 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; cursor: pointer; user-select: none;"></td><td id="LC42" class="js-file-line blob-code-inner blob-code" style="box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-size: 12px; overflow-wrap: normal; white-space: pre;">  <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">store</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">%_VtableFoo*</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">@_VtableFoo</span>, <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">%_VtableFoo**</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">%2</span></td></tr><tr style="box-sizing: border-box;" class=""><td id="L43" class="blob-num js-line-number" data-line-number="43" 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; cursor: pointer; user-select: none;"></td><td id="LC43" class="js-file-line blob-code-inner blob-code" style="box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-size: 12px; overflow-wrap: normal; white-space: pre;"><br class=""></td></tr><tr style="box-sizing: border-box;" class=""><td id="L47" class="blob-num js-line-number" data-line-number="47" 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; cursor: pointer; user-select: none;"></td><td id="LC47" class="js-file-line blob-code-inner blob-code" style="box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-size: 12px; overflow-wrap: normal; white-space: pre;"><span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">

<div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); 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;" class=""><a href="https://github.com/mukul-rathi/bolt/blob/vtable/src/llvm-backend/llvm_ir_codegen/expr_codegen.cc#L188:L202" 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="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Helvetica; white-space: normal;" class=""><br class=""></div><div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Helvetica; white-space: normal;" class=""><br class=""></div></span></td></tr><tr style="box-sizing: border-box;" class=""><td id="L48" class="blob-num js-line-number" data-line-number="48" 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; cursor: pointer; user-select: none;"></td><td id="LC48" class="js-file-line blob-code-inner blob-code" style="box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-size: 12px; overflow-wrap: normal; white-space: pre;">  <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">%5</span> = <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">load</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">%Foo*</span>, <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">%Foo**</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">%_var_y0</span></td></tr><tr style="box-sizing: border-box;" class=""><td id="L49" class="blob-num js-line-number" data-line-number="49" 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; cursor: pointer; user-select: none;"></td><td id="LC49" class="js-file-line blob-code-inner blob-code" style="box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-size: 12px; overflow-wrap: normal; white-space: pre;">  <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">%6</span> = <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">getelementptr</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">inbounds</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">%Foo</span>, <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">%Foo*</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">%5</span>, <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">i32</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">0</span>, <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">i32</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">0</span></td></tr><tr style="box-sizing: border-box;" class=""><td id="L50" class="blob-num js-line-number" data-line-number="50" 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; cursor: pointer; user-select: none;"></td><td id="LC50" class="js-file-line blob-code-inner blob-code" style="box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-size: 12px; overflow-wrap: normal; white-space: pre;">  <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">%7</span> = <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">load</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">%_VtableFoo*</span>, <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">%_VtableFoo**</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">%6</span></td></tr><tr style="box-sizing: border-box;" class=""><td id="L51" class="blob-num js-line-number" data-line-number="51" 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; cursor: pointer; user-select: none;"></td><td id="LC51" class="js-file-line blob-code-inner blob-code" style="box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-size: 12px; overflow-wrap: normal; white-space: pre;">  <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">%8</span> = <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">getelementptr</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">inbounds</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">%_VtableFoo</span>, <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">%_VtableFoo*</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">%7</span>, <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">i32</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">0</span>, <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">i32</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">0</span></td></tr><tr style="box-sizing: border-box;" class=""><td id="L52" class="blob-num js-line-number" data-line-number="52" 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; cursor: pointer; user-select: none;"></td><td id="LC52" class="js-file-line blob-code-inner blob-code" style="box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-size: 12px; overflow-wrap: normal; white-space: pre;">  <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">%9</span> = <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">load</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">void</span> (<span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">%Foo*</span>, <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">i32</span>)*, <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">void</span> (<span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">%Foo*</span>, <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">i32</span>)** <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">%8</span></td></tr><tr style="box-sizing: border-box;" class=""><td id="L53" class="blob-num js-line-number" data-line-number="53" 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; cursor: pointer; user-select: none;"></td><td id="LC53" class="js-file-line blob-code-inner blob-code" style="box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-size: 12px; overflow-wrap: normal; white-space: pre;"><br class=""></td></tr></tbody></table><div class=""><br class=""></div><div class=""><table class="js-file-line-container highlight tab-size" data-tab-size="8" data-paste-markdown-skip="" style="box-sizing: border-box; border-spacing: 0px; border-collapse: collapse; tab-size: 8; 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; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);"><tbody style="box-sizing: border-box;" class=""><tr style="box-sizing: border-box;" class=""><td id="L51" class="blob-num js-line-number" data-line-number="51" 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; cursor: pointer; user-select: none;"></td></tr></tbody></table><div class="">However, the builder->CreateLoad instruction corresponding to the line with %9 returns null:</div></div><div class=""><table class="js-file-line-container highlight tab-size" data-tab-size="8" data-paste-markdown-skip="" style="box-sizing: border-box; border-spacing: 0px; border-collapse: collapse; tab-size: 8; 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; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);"><tbody style="box-sizing: border-box;" class=""><tr style="box-sizing: border-box;" class=""></tr><tr style="box-sizing: border-box;" class=""><td id="LC202" class="js-file-line blob-code-inner blob-code" style="box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-size: 12px; overflow-wrap: normal; white-space: pre;">      <span style="font-variant-ligatures: normal;" class="">llvm::Function *calleeMethod = </span>llvm::dyn_cast<llvm::Function>(builder-><span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">CreateLoad</span>(calleeMethodPtr));
</td></tr><tr style="box-sizing: border-box;" class=""><td id="L203" class="blob-num js-line-number" data-line-number="203" 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; cursor: pointer; user-select: none;"></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; orphans: 2; white-space: pre; widows: 2; background-color: rgb(255, 255, 255);" class=""> builder-></span><span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197); font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-variant-ligatures: normal; orphans: 2; white-space: pre; widows: 2; 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; orphans: 2; white-space: pre; widows: 2; background-color: rgb(255, 255, 255);" class="">(calleeMethod, argVals);</span></div><div class=""><div style="orphans: 2; widows: 2;" class=""><font color="#24292e" face="SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace" class=""><span style="caret-color: rgb(36, 41, 46); white-space: pre; background-color: rgb(255, 255, 255);" class=""><br class=""></span></font></div><div style="orphans: 2; widows: 2;" class=""><font color="#24292e" face="SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace" class=""><span style="caret-color: rgb(36, 41, 46); white-space: pre; background-color: rgb(255, 255, 255);" class=""><br class=""></span></font></div><div style="orphans: 2; widows: 2;" 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 style="orphans: 2; widows: 2;" class=""><font color="#24292e" face="SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace" class=""><span style="caret-color: rgb(36, 41, 46); white-space: pre; background-color: rgb(255, 255, 255);" class=""><br class=""></span></font></div><div style="orphans: 2; widows: 2;" class=""><font color="#24292e" face="SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace" class=""><span style="caret-color: rgb(36, 41, 46); white-space: pre; background-color: rgb(255, 255, 255);" class=""><br class=""></span></font></div><div style="orphans: 2; widows: 2;" class=""><font color="#24292e" face="SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace" class=""><span style="caret-color: rgb(36, 41, 46); white-space: pre; background-color: rgb(255, 255, 255);" class=""><br class=""></span></font></div><div class=""><br class=""></div></div><div class=""><br class=""></div></body></html>