<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=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Mar 19, 2018, at 7:27 PM, Piotr Padlewski via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi folks,<div class=""><br class=""></div><div class="">here is a link to the proposal that we've been working on lately:</div><div class=""><a href="https://docs.google.com/document/d/16GVtCpzK8sIHNc2qZz6RN8amICNBtvjWUod2SujZVEo/edit?usp=sharing" target="_blank" class="">https://docs.google.com/<wbr class="">document/d/<wbr class="">16GVtCpzK8sIHNc2qZz6RN8amICNBt<wbr class="">vjWUod2SujZVEo/edit?usp=<wbr class="">sharing</a><br class=""></div><div class=""><br class=""></div><div class="">But for the record, I also paste it here. Feedback will be really appreciated!</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><b style="font-weight:normal" id="m_-8503527532884566477gmail-docs-internal-guid-a43ba0b5-406d-36b9-4e30-86e8c95f392a" class=""><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:3pt;text-align:center" class=""><span style="font-size: 26pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">RFC: C++ Devirtualization v2</span></p><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: center;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">Piotr Padlewski - </span><a href="mailto:piotr.padlewski@gmail.com" style="text-decoration:none" target="_blank" class=""><span style="font-size:11pt;font-family:Arial;color:rgb(17,85,204);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap" class="">piotr.padlewski@gmail.com</span></a></div><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: center;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">Krzysztof Pszeniczny - </span><a href="mailto:krzysztof.pszeniczny@gmail.com" style="text-decoration:none" target="_blank" class=""><span style="font-size:11pt;font-family:Arial;color:rgb(17,85,204);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap" class="">krzysztof.pszeniczny@gmail.com</span></a></div><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: center;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">Jakub Kuderski - </span><a href="mailto:kubakuderski@gmail.com" style="text-decoration:none" target="_blank" class=""><span style="font-size:11pt;font-family:Arial;color:rgb(17,85,204);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap" class="">kubakuderski@gmail.com</span></a></div><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: center;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">Richard Smith - </span><a href="mailto:RichardSmith@google.com" style="text-decoration:none" target="_blank" class=""><span style="font-size:11pt;font-family:Arial;color:rgb(17,85,204);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap" class="">RichardSmith@google.com</span></a></div><br class=""><br class=""><br class=""><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: justify;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">This proposal describes a new model of representing pointers to dynamic objects as “fat pointers”. It is designed to solve the hole in the previous devirtualization model that could cause miscompilation. We believe that solving this is very important, especially with the mitigation of the recent Spectre vulnerability - retpolines.</span></div><br class=""><h1 dir="ltr" style="line-height:1.38;margin-top:20pt;margin-bottom:6pt" class=""><span style="font-size: 20pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">Introduction to previous devirtualization</span></h1><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: justify;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">In the previous model we introduced </span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 700; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">invariant.group </span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">to LLVM as a way of saying “this load will produce the same value if given the same argument”, which was applied on loads from virtual pointer to communicate that virtual pointer (or in other words, dynamic type) does not change during the lifetime of an object. Because virtual pointer might be set multiple times during construction and destruction of derived types, and because it is possible to change the dynamic type of an object using placement new, </span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 700; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">invariant.group.barrier </span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">was introduced. It is used in every place where the dynamic type might change. To turn devirtualization on user had to specify the </span><span style="font-size: 11pt; font-family: Consolas; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">-fstrict-vtable-pointers</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> flag for clang. </span></div><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: justify;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">If you want to learn more about the previous model, check out [0][1][2][3]. Although the previous model is not sound for C++, languages like Java or Scala can safely use it. This is because virtual pointer in Java is set only once for every dynamic type, and you can’t do things like placement new, which means 2 aliasing pointers will always have the same dynamic type (also because every pointer still points to a valid object).</span></div><br class=""><h1 dir="ltr" style="line-height:1.38;margin-top:20pt;margin-bottom:6pt" class=""><span style="font-size: 20pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">The problem</span></h1><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">The old model miscompiles on the following example:</span></div><br class=""><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">A *a = new A;</span></div><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">a->foo(); </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""><br class="m_-8503527532884566477gmail-kix-line-break"></span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">A *b = new(a) B;</span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""><br class="m_-8503527532884566477gmail-kix-line-break"></span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">if (a == b)</span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""><br class="m_-8503527532884566477gmail-kix-line-break"></span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> b->foo(); // This call could be devirtualized to </span><span style="font-size:11pt;font-family:"Courier New";color:rgb(255,0,0);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">A::foo()</span></div><br class=""><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: justify;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">The problem is that GVN and other pass replaces the SSA value of </span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 700; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">b</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> with </span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 700; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">a </span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">based on the </span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 700; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">a==b</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> comparison, which is a totally legal optimization in LLVM and we surely still want to do it. In C++ however, If you replaced </span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 700; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">b </span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">with </span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 700; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">a </span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">inside the if statement’s body, then you would introduce UB. The problem arises because after changing %b to %a in LLVM, the load from virtual pointer can be devirtualized to different type. </span></div><br class=""><div style="line-height: 1.32955; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size:11pt;font-family:"Courier New";color:rgb(153,102,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">%vtable_a</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> = </span><span style="font-size:11pt;font-family:"Courier New";color:rgb(0,136,0);background-color:transparent;font-weight:700;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">load</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> </span><span style="font-size:11pt;font-family:"Courier New";color:rgb(153,102,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">%a</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">, </span><span style="font-size:11pt;font-family:"Courier New";color:rgb(153,102,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">!invariant.group</span></div><div style="line-height: 1.32955; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">;;;</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""><br class="m_-8503527532884566477gmail-kix-line-break"></span><span style="font-size:11pt;font-family:"Courier New";color:rgb(136,136,136);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">; %a == %b</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""><br class="m_-8503527532884566477gmail-kix-line-break"></span><span style="font-size:11pt;font-family:"Courier New";color:rgb(153,102,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">%bool</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> = </span><span style="font-size:11pt;font-family:"Courier New";color:rgb(0,136,0);background-color:transparent;font-weight:700;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">icmp</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> </span><span style="font-size:11pt;font-family:"Courier New";color:rgb(153,102,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">%a</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">, </span><span style="font-size:11pt;font-family:"Courier New";color:rgb(153,102,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">%b</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""><br class="m_-8503527532884566477gmail-kix-line-break"></span><span style="font-size:11pt;font-family:"Courier New";color:rgb(0,136,0);background-color:transparent;font-weight:700;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">br</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> </span><span style="font-size:11pt;font-family:"Courier New";color:rgb(153,102,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">%bool</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">, </span><span style="font-size:11pt;font-family:"Courier New";color:rgb(153,102,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">%if</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">, </span><span style="font-size:11pt;font-family:"Courier New";color:rgb(153,102,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">%after</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""><br class="m_-8503527532884566477gmail-kix-line-break"></span><span style="font-size:11pt;font-family:"Courier New";color:rgb(153,119,0);background-color:transparent;font-weight:700;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">if:</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""><br class="m_-8503527532884566477gmail-kix-line-break"></span><span style="font-size:11pt;font-family:"Courier New";color:rgb(136,136,136);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">; if this will be changed to %a, then the optimizer will be able to replace </span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""><br class="m_-8503527532884566477gmail-kix-line-break"></span><span style="font-size:11pt;font-family:"Courier New";color:rgb(136,136,136);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">; %vtable_b with %vtable_a</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""><br class="m_-8503527532884566477gmail-kix-line-break"></span><span style="font-size:11pt;font-family:"Courier New";color:rgb(153,102,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">%vtable_b</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> = </span><span style="font-size:11pt;font-family:"Courier New";color:rgb(0,136,0);background-color:transparent;font-weight:700;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">load</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> </span><span style="font-size:11pt;font-family:"Courier New";color:rgb(153,102,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">%b</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">, </span><span style="font-size:11pt;font-family:"Courier New";color:rgb(153,102,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">!invariant.group</span></div><br class=""><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">For other corner cases check out appendix.</span></div><h1 dir="ltr" style="line-height:1.38;margin-top:20pt;margin-bottom:6pt" class=""><span style="font-size: 20pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">Solution</span></h1><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: justify;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">The proposed solution is to model pointers to dynamic types as “fat pointers”. We can think of them as pointers that also store the current dynamic type. Virtual calls would consist of virtual pointer load from fat pointer. We will still use invariant.groups for the devirtualization. The difference is that accessing class field, or comparing pointers to dynamic objects would require a call to a new intrinsic - </span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 700; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">i8* llvm.strip.invariant.group(i8* )</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> to firstly get pointer without information about dynamic type. Creation (or reloading) of fat pointer would be done by call to new intrinsic - </span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 700; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">i8* llvm.launder.invariant.group(<wbr class="">i8*)</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> that </span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 700; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">replaces </span><span style="font-size:11pt;font-family:Arial;color:rgb(255,0,0);background-color:transparent;font-weight:700;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">llvm.invariant.group.barrier</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">.</span></div><br class=""><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: justify;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">The pointer comparison will now not be an issue, because the optimizer will not be able to replace the operand of a virtual pointer load with another pointer:</span></div><br class=""><br class=""><div style="line-height: 1.32955; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size:11pt;font-family:"Courier New";color:rgb(153,102,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">%vtable_a</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> = </span><span style="font-size:11pt;font-family:"Courier New";color:rgb(0,136,0);background-color:transparent;font-weight:700;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">load</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> </span><span style="font-size:11pt;font-family:"Courier New";color:rgb(0,136,0);background-color:transparent;font-weight:700;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">i8</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">* </span><span style="font-size:11pt;font-family:"Courier New";color:rgb(153,102,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">%a</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">, </span><span style="font-size:11pt;font-family:"Courier New";color:rgb(153,102,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">!invariant.group</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> !{}</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""><br class="m_-8503527532884566477gmail-kix-line-break"></span><span style="font-size:11pt;font-family:"Courier New";color:rgb(136,136,136);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">;;;</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""><br class="m_-8503527532884566477gmail-kix-line-break"></span><span style="font-size:11pt;font-family:"Courier New";color:rgb(136,136,136);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">; %a == %b</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""><br class="m_-8503527532884566477gmail-kix-line-break"></span><span style="font-size:11pt;font-family:"Courier New";color:rgb(153,102,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">%addr_a</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> = call i8* @</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:700;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">llvm.strip.invariant.group</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">(<wbr class="">i8* %a)</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""><br class="m_-8503527532884566477gmail-kix-line-break"></span><span style="font-size:11pt;font-family:"Courier New";color:rgb(153,102,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">%addr_b</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> = call i8* @</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:700;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">llvm.strip.invariant.group</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">(<wbr class="">i8* %b)</span></div><div style="line-height: 1.32955; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size:11pt;font-family:"Courier New";color:rgb(153,102,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">%bool</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> = </span><span style="font-size:11pt;font-family:"Courier New";color:rgb(0,136,0);background-color:transparent;font-weight:700;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">icmp</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> </span><span style="font-size:11pt;font-family:"Courier New";color:rgb(153,102,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">%addr_a</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">, </span><span style="font-size:11pt;font-family:"Courier New";color:rgb(153,102,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">%addr_b</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""><br class="m_-8503527532884566477gmail-kix-line-break"></span><span style="font-size:11pt;font-family:"Courier New";color:rgb(0,136,0);background-color:transparent;font-weight:700;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">br</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> </span><span style="font-size:11pt;font-family:"Courier New";color:rgb(153,102,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">%bool</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">, </span><span style="font-size:11pt;font-family:"Courier New";color:rgb(153,102,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">%if</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">, </span><span style="font-size:11pt;font-family:"Courier New";color:rgb(153,102,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">%after</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""><br class="m_-8503527532884566477gmail-kix-line-break"></span><span style="font-size:11pt;font-family:"Courier New";color:rgb(153,119,0);background-color:transparent;font-weight:700;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">if:</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""><br class="m_-8503527532884566477gmail-kix-line-break"></span><span style="font-size:11pt;font-family:"Courier New";color:rgb(136,136,136);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">; This will not be able to change %b to %a</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""><br class="m_-8503527532884566477gmail-kix-line-break"></span><span style="font-size:11pt;font-family:"Courier New";color:rgb(153,102,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">%vtable_b</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> = </span><span style="font-size:11pt;font-family:"Courier New";color:rgb(0,136,0);background-color:transparent;font-weight:700;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">load</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> </span><span style="font-size:11pt;font-family:"Courier New";color:rgb(0,136,0);background-color:transparent;font-weight:700;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">i8</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">* </span><span style="font-size:11pt;font-family:"Courier New";color:rgb(153,102,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">%b</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">, </span><span style="font-size:11pt;font-family:"Courier New";color:rgb(153,102,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">!invariant.group</span><span style="font-size:11pt;font-family:"Courier New";color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> !{}</span></div><br class=""><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: justify;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">It is important to notice that vtable load of %b cannot be replaced with a load of %addr_b Although the optimizer could potentially figure out that %b and %addr_b are aliasing, the aliasing rules are not strong enough to make this transformation valid. One counterexample could be that although both pointers are pointing to the same memory, one could be a pointer to mmap’ed memory with no write/load permission.</span></div><h1 dir="ltr" style="line-height:1.38;margin-top:20pt;margin-bottom:6pt;text-align:justify" class=""><span style="font-size: 20pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">The Solution formalized</span></h1><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: justify;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">Formally, to virtually mark pointers as optionally belonging to invariant groups subject to the following rules:</span></div><ul style="margin-top:0pt;margin-bottom:0pt" class=""><li dir="ltr" style="list-style-type: disc; font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: justify;" class=""><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">alloca</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> and library </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">malloc</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">-like functions return pointers belonging to fresh invariant groups</span></div></li><li dir="ltr" style="list-style-type: disc; font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: justify;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">belonging to an invariant group is preserved by bitcasts</span></div></li><li dir="ltr" style="list-style-type: disc; font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: justify;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">an intrinsic, </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">i8* llvm.strip.invariant.group(i8*<wbr class="">)</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> returns its argument with the invariant group virtual metadata stripped</span></div></li><li dir="ltr" style="list-style-type: disc; font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: justify;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">an intrinsic, </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">i8* llvm.launder.invariant.group(<wbr class="">i8*)</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> returns its argument with a fresh invariant group virtual metadata, i.e. it starts a new invariant group. This is similar to C++'s </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">std::launder</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">.</span></div></li><li dir="ltr" style="list-style-type: disc; font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: justify;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">every load and store marked </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">!invariant.group</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> from/to pointers belonging to the same invariant group must load/store the same value</span></div></li><li dir="ltr" style="list-style-type: disc; font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: justify;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">the behaviour of a load or store marked </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">!invariant.group</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> from/to pointers not belonging to any invariant group (e.g. obtained from </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">llvm.strip.invariant.group</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">) is undefined</span></div></li><li dir="ltr" style="list-style-type: disc; font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: justify;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">constructors may assume the </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">this</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> pointer passed to them belongs to a fresh invariant group</span></div></li></ul><br class=""><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: justify;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">From those rules one easily gets:</span></div><ul style="margin-top:0pt;margin-bottom:0pt" class=""><li dir="ltr" style="list-style-type: disc; font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: justify;" class=""><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">llvm.strip.invariant.group</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> is a pure function, i.e. its value depends only on its argument. Its llvm attributes include at least: </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">readnone speculatable nounwind</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">. Its results must alias its argument.</span></div></li><li dir="ltr" style="list-style-type: disc; font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: justify;" class=""><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">llvm.launder.invariant.group</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> is </span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 700; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">not</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> a pure function: it creates a fresh invariant group each time it's called. One may mentally model this as getting a fresh invariant group identifier somewhere from a 'magic' memory inaccessible to no-one else, so its llvm attributes include at least: </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">inaccessiblememonly speculatable nounwind</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">. Its results must alias its argument.</span></div></li><li dir="ltr" style="list-style-type: disc; font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: justify;" class=""><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">strip({strip,launder}(X)) = strip(X)</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">. This is because we do not care which particular invariant group metadata is stripped.</span></div></li><li dir="ltr" style="list-style-type: disc; font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: justify;" class=""><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">launder({strip,launder}(X))</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> may be replaced with </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">launder(X)</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> by the optimiser. Note that this not mean that </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">launder(launder(X)) = launder(X)</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">in the IR itself, but only on a metalanguage level: </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">launder</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> is inherently nondeterministic, so no two invocations of it ever return the same value.</span></div></li></ul><br class=""><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: justify;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">This allows to compile the following C++ constructs:</span></div><ul style="margin-top:0pt;margin-bottom:0pt" class=""><li dir="ltr" style="list-style-type: disc; font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: justify;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">vtable loads required to perform virtual calls are marked with </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">!invariant.group</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">, as before</span></div></li><li dir="ltr" style="list-style-type: disc; font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: justify;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">constructors of derived classes need to </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">launder</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> the </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">this</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> pointer before passing it to the constructors of base classes: they may subsequently operate on the original </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">this</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> pointer</span></div></li><li dir="ltr" style="list-style-type: disc; font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: justify;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">likewise, destructors of derived classes need to </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">launder</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> the </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">this</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> pointer before passing it to the destructors of base classes</span></div></li><li dir="ltr" style="list-style-type: disc; font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: justify;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">placement </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">new</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> and </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">std::launder</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> need to call </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">launder</span></div></li><li dir="ltr" style="list-style-type: disc; font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: justify;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">accesses to union members need to call </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">launder</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">, because the active member of the union may have changed since the last visible access</span></div></li><li dir="ltr" style="list-style-type: disc; font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: justify;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">whenever two pointers are to be compared, they must be </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">strip</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">ped first, because we want the comparison to provide information about the address equality, and not about invariant group equality</span></div></li><li dir="ltr" style="list-style-type: disc; font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: justify;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">likewise, whenever a pointer is to be cast to an integer type, it must be </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">strip</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">ped first</span></div></li><li dir="ltr" style="list-style-type: disc; font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: justify;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">whenever an integer is cast to a pointer type, the result must be </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">launder</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">ed before it is used, to prevent reasoning about the equality of integers to provide any information about equality of invariant groups</span></div></li></ul><br class=""><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: justify;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">Note that adding calls to </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">strip</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> and </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">launder</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> related to pointer comparisons and integer<->pointer conversions will not cause any semantic information to be lost: if any piece of information could be inferred by the optimiser about some collection of variables (e.g. that two pointers are equal) can be inferred now about their </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">strip</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">ped versions, no matter how many </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">strip</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> and </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">launder</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> calls have been made to obtain them in the IR. As an example, the C++ expression </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">ptr == std::launder(ptr)</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> will be optimised to </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">true</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">, because it will compare </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">strip(ptr)</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> with </span><span style="font-size: 11pt; font-family: "Courier New"; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">strip(launder(ptr))</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">, which are indeed equal according to our rules.</span></div></b></div></div></div></blockquote><div><br class=""></div><div>This proposal sounds great, even if it still doesn't solve some of the problems I personally need to solve with invariant loads. :)</div><div><br class=""></div><div>I take it that the actual devirtualization here is ultimately still done by forwarding a visible store of the v-table pointer to an invariant load, just by noticing that they occur to the same laundered pointer and therefore must involve the same value. There's no way of saying "I know what the value of the v-table pointer is even if you can't see a store" when creating a laundered pointer. For example, in Swift we have constructor functions that are known to return a complete object of a specific type, even if we can't necessarily see the implementation of that function; there's no way for us to say anything about that function pointer</div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><b style="font-weight:normal" id="m_-8503527532884566477gmail-docs-internal-guid-a43ba0b5-406d-36b9-4e30-86e8c95f392a" class=""><h2 dir="ltr" style="line-height:1.38;margin-top:18pt;margin-bottom:6pt" class=""><span style="font-size: 16pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">LLVM</span></h2><br class=""><br class=""><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: justify;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">Because LTO between a module with and without devirtualization will be invalid, we will need to break LLVM level ABI. This is however already implemented, because LTO between modules with invariant.group.barriers and without is also invalid. This also means that if we don’t want to break ABI between modules with and without optimizations, we will need to have invariant.barriers and fatpointer.create/strip turned on all the time. For the users it will means that when switching to new compiler, they will have to recompile all of the generated object files for LTO builds.</span></div></b></div></div></div></blockquote><div><br class=""></div>Is there really no way to have this degrade more gracefully? I continue to be very concerned about frontend interworking here, either between different versions of a single frontend (e.g. clang 6 vs. clang 8), or between different invocations of a single frontend with different language options set (e.g. clang vs. clang++), or even between different frontends that produce IR that gets linked together (e.g. clang vs. swift).</div><div><br class=""></div><div>How about this approach:</div><div> - Instead of taking a meaningless !{} argument, invariant.group takes a string argument which identifies a metadata-dependent optimization. In your case, it would be something like !"clang.cxx_devirtualization".</div><div> - Functions have a "supported optimizations" list which declares all the metadata-reliant optimizations they promise to have correct metadata for. So e.g. clang++ would list "clang.cxx_devirtualization" on every single function it compiled, regardless of whether that function actually needed any metadata. I'm pretty sure metadata are optimized so that identical lists of options like this don't take up more space just because they're added to every single function in the module.</div><div> - Interprocedural optimizations — which mostly means inlining — are required to be aware of the supported-optimizations list. The inliner would intersect the supported-optimizations lists and then strip metadata/intrinsics that don't belong anymore.</div><div><br class=""></div><div>But the idea that every single metadata-dependent optimization is going to create a new "IR ABI break" just seems unacceptable to me. Compiler optimization IRs are not stable things; compiler engineers constantly find new things that they want to express.</div><div><br class=""></div><div>John.</div><div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><b style="font-weight:normal" id="m_-8503527532884566477gmail-docs-internal-guid-a43ba0b5-406d-36b9-4e30-86e8c95f392a" class=""><h2 dir="ltr" style="line-height:1.38;margin-top:18pt;margin-bottom:6pt" class=""><span style="font-size: 16pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">Clang</span></h2><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">Clang will require a couple of minor changes in CodeGen for constructors and destructors.</span></div><br class=""><br class=""><h1 dir="ltr" style="line-height:1.38;margin-top:20pt;margin-bottom:6pt" class=""><span style="font-size: 20pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""><b style="font-weight:normal" id="gmail-docs-internal-guid-62489d1e-4094-c892-40fb-463ebc9fab54" class=""><h1 dir="ltr" style="line-height:1.38;margin-top:20pt;margin-bottom:6pt" class=""><span style="font-size: 20pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">Acknowledgment</span></h1><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">Special thanks for the initiators of this idea - Richard Smith, Chandler Carruth and Sanjoy Das and also for all the other people who took a part in helping with devirtualization v1 including: Daniel Berlin, Reid Kleckner, David Majnemer, John McCall.</span></div></b><br class="gmail-Apple-interchange-newline">References</span></h1><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">[0] - Devirtualization in LLVM, Proceeding SPLASH Companion 2017 Proceedings Companion of the 2017 ACM SIGPLAN International Conference on Systems, Programming, Languages, and Applications: Software for Humanity - </span><a href="https://dl.acm.org/citation.cfm?id=3135947" style="text-decoration:none" target="_blank" class=""><span style="font-size:11pt;font-family:Arial;color:rgb(17,85,204);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap" class="">https://dl.acm.org/citation.<wbr class="">cfm?id=3135947</span></a></div><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">[1] - RFC: Devirtualization in LLVM (ver 1) - </span><a href="https://docs.google.com/document/d/1f2SGa4TIPuBGm6y6YO768GrQsA8awNfGEJSBFukLhYA/edit?usp=sharing" style="text-decoration:none" target="_blank" class=""><span style="font-size:11pt;font-family:Arial;color:rgb(17,85,204);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap" class="">https://docs.google.com/<wbr class="">document/d/<wbr class="">1f2SGa4TIPuBGm6y6YO768GrQsA8aw<wbr class="">NfGEJSBFukLhYA/edit?usp=<wbr class="">sharing</span></a></div><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">[2] - Devirtualization in LLVM - LLVM Dev meeting 2016 - </span><a href="https://www.youtube.com/watch?v=qMhV6d3B1Vk" style="text-decoration:none" target="_blank" class=""><span style="font-size:11pt;font-family:Arial;color:rgb(17,85,204);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap" class="">https://www.youtube.com/watch?<wbr class="">v=qMhV6d3B1Vk</span></a></div><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">[3] - Devirtualization in LLVM and Clang - llvm blog- </span><a href="http://blog.llvm.org/2017/03/devirtualization-in-llvm-and-clang.html" style="text-decoration:none" target="_blank" class=""><span style="font-size:11pt;font-family:Arial;color:rgb(17,85,204);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap" class="">http://blog.llvm.org/2017/03/<wbr class="">devirtualization-in-llvm-and-<wbr class="">clang.html</span></a></div><br class=""><br class=""><br class=""><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:3pt" class=""><span style="font-size: 26pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">Appendix</span></p><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">Here are some other corner cases that we found.</span></div><h1 dir="ltr" style="line-height:1.38;margin-top:20pt;margin-bottom:6pt" class=""><span style="font-size: 20pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">Unions</span></h1><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-align: justify;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">Because union can have dynamic types as members, this means that they would have the same address. To solve this we emit launder.invariant.group before getting any dynamic type. It is possible that we could somehow avoid it, but because virtually no one is using unions this way, this should not cause any problems.</span></div><br class=""><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size:10.5pt;font-family:Verdana;color:rgb(0,0,255);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">struct</span><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> A {</span></div><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> </span><span style="font-size:10.5pt;font-family:Verdana;color:rgb(0,0,255);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">virtual</span><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> </span><span style="font-size:10.5pt;font-family:Verdana;color:rgb(0,0,255);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">void</span><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> foo();</span></div><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">};</span></div><br class=""><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size:10.5pt;font-family:Verdana;color:rgb(0,0,255);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">struct</span><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> B : A {</span></div><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> </span><span style="font-size:10.5pt;font-family:Verdana;color:rgb(0,0,255);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">void</span><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> foo() </span><span style="font-size:10.5pt;font-family:Verdana;color:rgb(0,0,255);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">override</span><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">;</span></div><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">};</span></div><br class=""><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size:10.5pt;font-family:Verdana;color:rgb(0,0,255);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">union</span><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> U {</span></div><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> A a;</span></div><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> B b;</span></div><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> U() : b() {}</span></div><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">};</span></div><br class=""><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size:10.5pt;font-family:Verdana;color:rgb(0,0,255);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">void</span><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> do_call(A &a) {</span></div><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> a.foo();</span></div><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">}</span></div><br class=""><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">__attribute__((noinline)) </span><span style="font-size:10.5pt;font-family:Verdana;color:rgb(0,0,255);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">void</span><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> init_B(U &u) {</span></div><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> </span><span style="font-size:10.5pt;font-family:Verdana;color:rgb(0,0,255);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">new</span><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">(&u.b) B;</span></div><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">}</span></div><br class=""><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size:10.5pt;font-family:Verdana;color:rgb(0,0,255);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">void</span><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> union_test(U &u) {</span></div><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> do_call(u.b);</span></div><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> </span><span style="font-size:10.5pt;font-family:Verdana;color:rgb(0,0,255);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">new</span><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">(&u.a) A;</span></div><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> do_call(u.a);</span></div><br class=""><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> init_B(u);</span></div><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> do_call(u.b);</span></div><br class=""><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">}</span></div><br class=""><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size:10.5pt;font-family:Verdana;color:rgb(0,0,255);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">int</span><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> main() {</span></div><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> U u;</span></div><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> union_test(u);</span></div><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">}</span></div><h1 dir="ltr" style="line-height:1.38;margin-top:20pt;margin-bottom:6pt" class=""><span style="font-size: 20pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">Ptr to int</span></h1><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">In this example, instead of comparing the pointers we compare the addresses stored in integers. Because ptrtoint conversion will also require call to </span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 700; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">strip.invariant.group</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">, this will also work.</span></div><br class=""><br class=""><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size:10.5pt;font-family:Verdana;color:rgb(0,0,255);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">void</span><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> ptr_to_int() {</span></div><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> A *a = </span><span style="font-size:10.5pt;font-family:Verdana;color:rgb(0,0,255);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">new</span><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> A;</span></div><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> a->foo();</span></div><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> A *b = </span><span style="font-size:10.5pt;font-family:Verdana;color:rgb(0,0,255);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">new</span><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">(a) B;</span></div><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> </span><span style="font-size:10.5pt;font-family:Verdana;color:rgb(0,0,255);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">auto</span><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> av = (</span><span style="font-size:10.5pt;font-family:Verdana;color:rgb(0,0,255);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">uintptr_t</span><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">)a;</span></div><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> </span><span style="font-size:10.5pt;font-family:Verdana;color:rgb(0,0,255);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">auto</span><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> bv = (</span><span style="font-size:10.5pt;font-family:Verdana;color:rgb(0,0,255);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">uintptr_t</span><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">)b;</span></div><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> </span><span style="font-size:10.5pt;font-family:Verdana;color:rgb(0,0,255);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">if</span><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> (av == bv)</span></div><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> b->foo();</span></div><div style="line-height: 1.62857; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 10.5pt; font-family: Verdana; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">}</span></div><br class=""><br class=""><h1 dir="ltr" style="line-height:1.38;margin-top:20pt;margin-bottom:6pt" class=""><span style="font-size: 20pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">int to ptr</span></h1><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">Here because we are creating a fat pointer from integer, we need to use launder:</span></div><br class=""><div style="line-height: 1.32955; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,153);background-color:transparent;font-weight:700;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">void</span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> </span><span style="font-size:11pt;font-family:Arial;color:rgb(0,102,187);background-color:transparent;font-weight:700;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">foo</span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">(Base *base) {</span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""><br class="m_-8503527532884566477gmail-kix-line-break"></span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> </span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,153);background-color:transparent;font-weight:700;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">uintptr_t</span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> base_int = (</span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,153);background-color:transparent;font-weight:700;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">uintptr_t</span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">)base;</span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""><br class="m_-8503527532884566477gmail-kix-line-break"></span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> </span><span style="font-size:11pt;font-family:Arial;color:rgb(136,136,136);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">/* base_int = ptrtoint (strip base) */</span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""><br class="m_-8503527532884566477gmail-kix-line-break"></span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> Base *base_int_ptr = (Base*)base_int;</span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""><br class="m_-8503527532884566477gmail-kix-line-break"></span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> </span><span style="font-size:11pt;font-family:Arial;color:rgb(136,136,136);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">/* base_int_ptr = inttoptr base_int = inttoptr (ptrtoint (strip base)) = strip base */</span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""><br class="m_-8503527532884566477gmail-kix-line-break"></span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> base_int_ptr->vfun();</span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""><br class="m_-8503527532884566477gmail-kix-line-break"></span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> ...</span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""><br class="m_-8503527532884566477gmail-kix-line-break"></span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> Derived *derived = std::launder(base);</span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""><br class="m_-8503527532884566477gmail-kix-line-break"></span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> </span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,153);background-color:transparent;font-weight:700;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">uintptr_t</span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> derived_int = (</span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,153);background-color:transparent;font-weight:700;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">uintptr_t</span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">)derived;</span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""><br class="m_-8503527532884566477gmail-kix-line-break"></span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> </span><span style="font-size:11pt;font-family:Arial;color:rgb(136,136,136);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">/* derived_int = ptrtoint (strip derived) */</span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""><br class="m_-8503527532884566477gmail-kix-line-break"></span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> </span><span style="font-size:11pt;font-family:Arial;color:rgb(136,136,136);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">/* Note: base_int == derived_int */</span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""><br class="m_-8503527532884566477gmail-kix-line-break"></span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> ....</span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""><br class="m_-8503527532884566477gmail-kix-line-break"></span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> Base *derived_int_ptr = (Base*)derived_int;</span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""><br class="m_-8503527532884566477gmail-kix-line-break"></span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> </span><span style="font-size:11pt;font-family:Arial;color:rgb(136,136,136);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">/* derived_int_ptr = inttoptr (ptrtoint (strip derived)) */</span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""><br class="m_-8503527532884566477gmail-kix-line-break"></span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> </span><span style="font-size:11pt;font-family:Arial;color:rgb(136,136,136);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">/* Note: base_int_ptr == derived_int_ptr */</span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""><br class="m_-8503527532884566477gmail-kix-line-break"></span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> derived_int_ptr->vfun();</span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""><br class="m_-8503527532884566477gmail-kix-line-break"></span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""> </span><span style="font-size:11pt;font-family:Arial;color:rgb(136,136,136);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">/* BUG: But it's different than base_int_ptr->vfun()! */</span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class=""><br class="m_-8503527532884566477gmail-kix-line-break"></span><span style="font-size:11pt;font-family:Arial;color:rgb(51,51,51);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap" class="">}</span></div><br class=""></b><br class=""></div></div>
_______________________________________________<br class="">cfe-dev mailing list<br class=""><a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a><br class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev<br class=""></div></blockquote></div><br class=""></body></html>