<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Mangal;
        panose-1:0 0 4 0 0 0 0 0 0 0;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">I think Clang, on/for windows, should give a compile time flag/option that can be used to control it (A flag when set make compile-time operator like
<span style="color:blue">sizeoff</span> to behave like MSVC or non-MSVC)  As in the current form it is breaking building of cross-platform application.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">With C++11 onward many things are incorporated in standard so that one code base can be used across platform. Now if compiler is blocking the flow then it seems moving back to pre C++11.
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> David Blaikie <dblaikie@gmail.com> <br>
<b>Sent:</b> Friday, January 29, 2021 3:23 AM<br>
<b>To:</b> Vivek Pandey <vivek.pandey@tallysolutions.com><br>
<b>Cc:</b> cfe-users@lists.llvm.org; Manu Agarwal <manu.agarwal@tallysolutions.com>; Tuhin Sengupta <tuhin.sengupta@tallysolutions.com><br>
<b>Subject:</b> Re: [cfe-users] Clang Sizeof give diff value for Microsoft and Linux<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">Clang on Windows is designed to be compatible with MSVC - which has different layout requirements than the Itanium ABI/GCC on Linux. I don't think there's a way to use the same ABI on both platforms - especially not if you are interacting
 with any code compiled by another compiler on both platforms (existing/foregin C++ precompiled libraries).<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">On Thu, Jan 28, 2021 at 1:45 PM Vivek Pandey via cfe-users <<a href="mailto:cfe-users@lists.llvm.org">cfe-users@lists.llvm.org</a>> wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Hi Team,<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">We are using Clang 11 for our product that has common C++ code base for Windows, Linux, Macintosh, ….<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">We observed that
<span style="color:black;background:yellow">sizeof</span> operator gives different value on Windows and Linux/OSX, when the inheritance is from a common base class:<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Example Sample:<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:8.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:45.8pt">
<span style="font-size:8.0pt;font-family:"Courier New"">#include <cassert></span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:45.8pt">
<span style="font-size:8.0pt;font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:45.8pt">
<span style="font-size:8.0pt;font-family:"Courier New"">struct Base {}; // empty class</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:45.8pt">
<span style="font-size:8.0pt;font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:45.8pt">
<span style="font-size:8.0pt;font-family:"Courier New"">struct Derived1 : Base {</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:45.8pt">
<span style="font-size:8.0pt;font-family:"Courier New"">    int i;</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:45.8pt">
<span style="font-size:8.0pt;font-family:"Courier New"">};</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:45.8pt">
<span style="font-size:8.0pt;font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:45.8pt">
<span style="font-size:8.0pt;font-family:"Courier New"">struct Derived2 : Base {</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:45.8pt">
<span style="font-size:8.0pt;font-family:"Courier New"">    Base c; // Base, occupies 1 byte, followed by padding for i</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:45.8pt">
<span style="font-size:8.0pt;font-family:"Courier New"">    int i;</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:45.8pt">
<span style="font-size:8.0pt;font-family:"Courier New"">};</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:45.8pt">
<span style="font-size:8.0pt;font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:45.8pt">
<span style="font-size:8.0pt;font-family:"Courier New"">struct Derived3 : Base {</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:45.8pt">
<span style="font-size:8.0pt;font-family:"Courier New"">    Derived1 c; // <span style="color:black;background:yellow">
Derived1 is too derived from same Base class</span></span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:45.8pt">
<span style="font-size:8.0pt;font-family:"Courier New"">    int i;</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:45.8pt">
<span style="font-size:8.0pt;font-family:"Courier New"">};</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:45.8pt">
<span style="font-size:8.0pt;font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:45.8pt">
<span style="font-size:8.0pt;font-family:"Courier New"">int main()</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:45.8pt">
<span style="font-size:8.0pt;font-family:"Courier New"">{</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:45.8pt">
<span style="font-size:8.0pt;font-family:"Courier New"">    <a href="https://ind01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fen.cppreference.com%2Fw%2Fcpp%2Ferror%2Fassert&data=04%7C01%7Cvivek.pandey%40tallysolutions.com%7C1a2156b9e1d146b7360608d8c3d71ae2%7C66bcd9b727254893bb969ae424774af6%7C0%7C0%7C637474675935486094%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000&sdata=NYeOWjC%2B0xhCxaFWPvJTpcN9xvz8uCZDV5gAKEan8J0%3D&reserved=0" target="_blank">
assert</a>(sizeof(Derived2) == 2*sizeof(int));</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:45.8pt">
<span style="font-size:8.0pt;font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:45.8pt">
<span style="font-size:8.0pt;font-family:"Courier New"">    <a href="https://ind01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fen.cppreference.com%2Fw%2Fcpp%2Ferror%2Fassert&data=04%7C01%7Cvivek.pandey%40tallysolutions.com%7C1a2156b9e1d146b7360608d8c3d71ae2%7C66bcd9b727254893bb969ae424774af6%7C0%7C0%7C637474675935496090%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000&sdata=ymboJjAMIu8lm26ZdA7L%2FArWNyxIUUu96c89R5f4oR8%3D&reserved=0" target="_blank">
assert</a>(<span style="color:black;background:yellow">sizeof(Derived3)</span> == 3*sizeof(int));</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:45.8pt">
<span style="font-size:8.0pt;font-family:"Courier New"">}</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">              When we compile above program using Clang 11 and run it on windows and Linux  sizeof(<span style="font-size:10.0pt;font-family:"Courier New";color:black;background:yellow">Derived3</span>)
 give different value.<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">We don’t want a work-around via making first data member of derived class of type different from class that also is derived from same empty base class.<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Is there any flag that we can use so that it gives same result on all platform (Windows/Linux/OSX/Android/iOS/….)<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Or another way to solve this gracefully.
<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Thank you!<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Best Regards,<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Vivek<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
</div>
</div>
<p class="MsoNormal">_______________________________________________<br>
cfe-users mailing list<br>
<a href="mailto:cfe-users@lists.llvm.org" target="_blank">cfe-users@lists.llvm.org</a><br>
<a href="https://ind01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.llvm.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fcfe-users&data=04%7C01%7Cvivek.pandey%40tallysolutions.com%7C1a2156b9e1d146b7360608d8c3d71ae2%7C66bcd9b727254893bb969ae424774af6%7C0%7C0%7C637474675935496090%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000&sdata=jAVCIt7Ty9mpi84hTN3aZKNLj8oHTmEYcmNW4anhe7I%3D&reserved=0" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users</a><o:p></o:p></p>
</blockquote>
</div>
</div>
</body>
</html>