<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 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";
        color:black;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";
        color:black;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:"Consolas","serif";
        color:black;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@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 bgcolor="white" lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">The DWARF attribute should be attached to whatever entity is over-aligned in the source.  The cppreference.com description says C11's _Alignas applies to object
 declarations, rather than types, although putting it on a struct member will implicitly propagate to the containing struct type.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">In this example, clearly the variable DIE for 'd' needs DW_AT_alignment(2048).  However, that's not sufficient, because if you had some other variable 'struct
 data x;' without an explicit alignment, you still need to specify that 'x.cacheline' is over-aligned.  That means you also need DW_AT_alignment(128) on the member DIE for 'cacheline'.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">It's debatable whether to put DW_AT_alignment(128) on the type DIE for 'struct data' as well, because of the implicit propagation.  The argument against doing
 that is that consumers have always had to look at the content of the struct to determine its alignment, so putting it on the 'cacheline' member should be sufficient (a DWARF 5 consumer could reasonably be expected to notice the alignment attribute, given that
 it has to look at the member DIEs anyway).<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">There's no reason to put DW_AT_alignment on anything related to the array type description or the base type.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">--paulr<o:p></o:p></span></p>
<p class="MsoNormal"><a name="_MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></a></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext"> llvm-dev [mailto:llvm-dev-bounces@lists.llvm.org]
<b>On Behalf Of </b>Victor Leschuk via llvm-dev<br>
<b>Sent:</b> Thursday, September 08, 2016 1:08 AM<br>
<b>To:</b> LLVM Dev<br>
<b>Subject:</b> [llvm-dev] DWARFv5 alignment attribute<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Hello all, I am currently implementing support for DWARFv5 DW_AT_alignment attribute (<a href="http://www.dwarfstd.org/ShowIssue.php?issue=140528.1">http://www.dwarfstd.org/ShowIssue.php?issue=140528.1</a>). I am not 100% sure which entities
 we should mark with this attr.<br>
<br>
Consider the following C11 code (sample from <a href="http://en.cppreference.com/w/c/language/_Alignas">
http://en.cppreference.com/w/c/language/_Alignas</a>):<br>
<br>
// every object of type struct data will be aligned to 128-byte boundary <br>
struct data { <br>
char x; <br>
_Alignas(128) char cacheline[128]; // over-aligned array of char, <br>
// not array of over-aligned chars <br>
}; <br>
<br>
int main(void) <br>
{ <br>
_Alignas(2048) struct data d; // this instance of data is aligned even stricter<br>
return 0; <br>
} <br>
<br>
What should be marked as DW_AT_alignment? The link above says that the attribute can be applied to:
<o:p></o:p></p>
<pre><span style="font-size:12.0pt">DW_TAG_array_type, DW_TAG_atomic_type, DW_TAG_base_type, DW_TAG_class_type,<o:p></o:p></span></pre>
<pre><span style="font-size:12.0pt">DW_TAG_coarray_type, DW_TAG_const_type, DW_TAG_dynamic_type,<o:p></o:p></span></pre>
<pre><span style="font-size:12.0pt">DW_TAG_enumeration_type, DW_TAG_file_type, DW_TAG_interface_type,<o:p></o:p></span></pre>
<pre><span style="font-size:12.0pt">DW_TAG_packed_type, DW_TAG_pointer_type, DW_TAG_pointer_to_member_type,<o:p></o:p></span></pre>
<pre><span style="font-size:12.0pt">DW_TAG_reference_type, DW_TAG_restrict_type, DW_TAG_rvalue_reference_type,<o:p></o:p></span></pre>
<pre><span style="font-size:12.0pt">DW_TAG_set_type, DW_TAG_shared_type, DW_TAG_string_type, DW_TAG_structure_type,<o:p></o:p></span></pre>
<pre><span style="font-size:12.0pt">DW_TAG_subprogram, DW_TAG_subrange_type, DW_TAG_subroutine_type,<o:p></o:p></span></pre>
<pre><span style="font-size:12.0pt">DW_TAG_thrown_type, DW_TAG_typedef, DW_TAG_union_type, DW_TAG_variable</span><o:p></o:p></pre>
<p class="MsoNormal" style="margin-bottom:12.0pt"><br>
 Here we have<br>
<br>
* DW_TAG_array_type<br>
* DW_TAG_subrange_type<br>
* DW_TAG_member <br>
* DW_TAG_structure_type<br>
* DW_TAG_basic_type<br>
* DW_TAG_variable<br>
<br>
Currently I mark only variable "d" as aligned, however I am not sure, that this is correct? Which of the listed should contain this attribute? What do you think?<br>
<br>
--<br>
Victor<o:p></o:p></p>
</div>
</div>
</body>
</html>